generated from alleyinteractive/create-wordpress-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/LEDE-2667/wp-cleanup-spacing
- Loading branch information
Showing
12 changed files
with
243 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { useEffect, useMemo, useState } from '@wordpress/element'; | ||
import apiFetch from '@wordpress/api-fetch'; | ||
import useNewsletterMeta from '@/hooks/useNewsletterMeta'; | ||
|
||
interface ListResult { | ||
ListID: string; | ||
Name: string; | ||
} | ||
|
||
export interface Option { | ||
value: string; | ||
label: string; | ||
} | ||
|
||
function useEmailLists() { | ||
const { meta } = useNewsletterMeta(); | ||
const [lists, setLists] = useState<ListResult[]>([]); | ||
|
||
const emailListOptions = useMemo(() => { | ||
if (lists.length === 0) { | ||
return []; | ||
} | ||
|
||
return lists | ||
.map((item: ListResult) => ({ label: item.Name, value: item.ListID })); | ||
}, [lists]); | ||
const selectedEmailList = useMemo(() => emailListOptions | ||
.filter((item: Option) => meta.list.includes(item.value)), [meta.list, emailListOptions]); | ||
|
||
useEffect(() => { // eslint-disable-line | ||
if (lists.length > 0) { | ||
return; | ||
} | ||
apiFetch({ path: '/wp-newsletter-builder/v1/lists' }).then((response) => { | ||
setLists(response as any as ListResult[]); | ||
}); | ||
}, [lists]); | ||
|
||
return { | ||
emailListOptions, | ||
selectedEmailList, | ||
}; | ||
} | ||
|
||
export default useEmailLists; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { usePostMeta } from '@alleyinteractive/block-editor-tools'; | ||
|
||
export interface NewsletterMeta { | ||
type: string; | ||
template: string; | ||
fromName: string; | ||
subject: string; | ||
preview: string; | ||
list: string[]; | ||
image: number; | ||
send: boolean; | ||
content: string; | ||
sentBreakingPostId: number[]; | ||
} | ||
|
||
function useNewsletterMeta() { | ||
const [meta, setMeta] = usePostMeta(); | ||
|
||
const { | ||
nb_breaking_email_type: type = '', | ||
nb_breaking_template: template = '', | ||
nb_breaking_from_name: fromName = '', | ||
nb_breaking_subject: subject = '', | ||
nb_breaking_preview: preview = '', | ||
nb_breaking_list: list = [], | ||
nb_breaking_header_img: image = 0, | ||
nb_breaking_should_send: send = false, | ||
nb_breaking_content: content = '', | ||
nb_newsletter_sent_breaking_post_id: sentBreakingPostId = [], | ||
} = meta; | ||
|
||
return { | ||
meta: { | ||
type, | ||
template, | ||
fromName, | ||
subject, | ||
preview, | ||
list, | ||
image, | ||
send, | ||
content, | ||
sentBreakingPostId, | ||
}, | ||
setMeta, | ||
}; | ||
} | ||
|
||
export default useNewsletterMeta; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
plugins/newsletter-from-post/components/required-fields.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { __ } from '@wordpress/i18n'; | ||
import { NewsletterMeta } from '@/hooks/useNewsletterMeta'; | ||
|
||
interface RequiredFieldsProps { | ||
meta: Pick<NewsletterMeta, 'type' | 'template' | 'fromName' | 'subject' | 'preview' | 'list'> | ||
postTitle: string; | ||
postExcerpt: string; | ||
} | ||
|
||
function RequiredFields({ meta, postTitle, postExcerpt }: RequiredFieldsProps) { | ||
return ( | ||
<> | ||
{!meta.type ? ( | ||
<p style={{ color: 'red' }}>{__('Header Type is Required', 'wp-newsletter-builder')}</p> | ||
) : null} | ||
{!meta.template ? ( | ||
<p style={{ color: 'red' }}>{__('Template is Required', 'wp-newsletter-builder')}</p> | ||
) : null} | ||
{!meta.fromName ? ( | ||
<p style={{ color: 'red' }}>{__('From Name is Required', 'wp-newsletter-builder')}</p> | ||
) : null} | ||
{!meta.subject && !postTitle ? ( | ||
<p style={{ color: 'red' }}>{__('Subject is Required', 'wp-newsletter-builder')}</p> | ||
) : null} | ||
{!meta.preview && !postExcerpt ? ( | ||
<p style={{ color: 'red' }}>{__('Preview Text is Required', 'wp-newsletter-builder')}</p> | ||
) : null} | ||
{meta.list.length === 0 ? ( | ||
<p style={{ color: 'red' }}>{__('Email List is Required', 'wp-newsletter-builder')}</p> | ||
) : null} | ||
</> | ||
); | ||
} | ||
|
||
export default RequiredFields; |
File renamed without changes.
Oops, something went wrong.