Skip to content

Commit

Permalink
Merge branch 'develop' into feature/LEDE-2667/wp-cleanup-spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
cahdeemer committed Jun 12, 2024
2 parents 8106b5f + c1092bd commit 4b94306
Show file tree
Hide file tree
Showing 12 changed files with 243 additions and 115 deletions.
1 change: 1 addition & 0 deletions .phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<!-- Exclude a few directories and autogenerated files. -->
<exclude-pattern>build/</exclude-pattern>
<exclude-pattern>vendor/</exclude-pattern>
<exclude-pattern>tests/</exclude-pattern>

<!-- The version set here matches the minimum version tested in buddy.yml. -->
<config name="minimum_supported_wp_version" value="5.9" />
Expand Down
10 changes: 5 additions & 5 deletions blocks/footer/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,31 +80,31 @@ export default function Edit() {
{facebookUrl
? (
<span className="wp-block-wp-newsletter-builder-footer__social-links__item">
<a className="wp-block-wp-newsletter-builder-footer__social-links__link" href={facebookUrl}>
<a className="wp-block-wp-newsletter-builder-footer__social-links__link facebook-icon" href={facebookUrl}>
<img src="/wp-content/plugins/wp-newsletter-builder/images/facebook.png" alt="Facebook" height="26" width="26" />
</a>
</span>
) : null}
{twitterUrl
? (
<span className="wp-block-wp-newsletter-builder-footer__social-links__item">
<a className="wp-block-wp-newsletter-builder-footer__social-links__link" href={twitterUrl}>
<img src="/wp-content/plugins/wp-newsletter-builder/images/twitter.png" alt="Twitter" height="26" width="26" />
<a className="wp-block-wp-newsletter-builder-footer__social-links__link twitter-icon" href={twitterUrl}>
<img src="/wp-content/plugins/wp-newsletter-builder/images/twitter.png" alt="X" height="26" width="26" />
</a>
</span>
) : null}
{instagramUrl
? (
<span className="wp-block-wp-newsletter-builder-footer__social-links__item">
<a className="wp-block-wp-newsletter-builder-footer__social-links__link" href={instagramUrl}>
<a className="wp-block-wp-newsletter-builder-footer__social-links__link instagram-icon" href={instagramUrl}>
<img src="/wp-content/plugins/wp-newsletter-builder/images/instagram.png" alt="Instagram" height="26" width="26" />
</a>
</span>
) : null}
{youtubeUrl
? (
<span className="wp-block-wp-newsletter-builder-footer__social-links__item">
<a className="wp-block-wp-newsletter-builder-footer__social-links__link" href={youtubeUrl}>
<a className="wp-block-wp-newsletter-builder-footer__social-links__link youtube-icon" href={youtubeUrl}>
<img src="/wp-content/plugins/wp-newsletter-builder/images/youtube.png" alt="YouTube" height="26" width="26" />
</a>
</span>
Expand Down
36 changes: 28 additions & 8 deletions blocks/footer/render.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,49 @@
<div class="wp-block-wp-newsletter-builder-footer__social-links">
<?php if ( ! empty( $nb_facebook_url ) ) : ?>
<span class="wp-block-wp-newsletter-builder-footer__social-links__item">
<a class="wp-block-wp-newsletter-builder-footer__social-links__link" href="<?php echo esc_url( $nb_facebook_url ); ?>">
<img src="/wp-content/plugins/wp-newsletter-builder/images/facebook.png" alt="Facebook" height="26" width="26" />
<a class="wp-block-wp-newsletter-builder-footer__social-links__link facebook-icon" href="<?php echo esc_url( $nb_facebook_url ); ?>">
<img
src="<?php echo esc_url( home_url() . '/wp-content/plugins/wp-newsletter-builder/images/facebook.png' ); ?>"
alt="Facebook"
height="26"
width="26"
/>
</a>
</span>
<?php endif; ?>
<?php if ( ! empty( $nb_twitter_url ) ) : ?>
<span class="wp-block-wp-newsletter-builder-footer__social-links__item">
<a class="wp-block-wp-newsletter-builder-footer__social-links__link" href="<?php echo esc_url( $nb_twitter_url ); ?>">
<img src="/wp-content/plugins/wp-newsletter-builder/images/twitter.png" alt="Twitter" height="26" width="26" />
<a class="wp-block-wp-newsletter-builder-footer__social-links__link twitter-icon" href="<?php echo esc_url( $nb_twitter_url ); ?>">
<img
src="<?php echo esc_url( home_url() . '/wp-content/plugins/wp-newsletter-builder/images/twitter.png' ); ?>"
alt="Twitter"
height="26"
width="26"
/>
</a>
</span>
<?php endif; ?>
<?php if ( ! empty( $nb_instagram_url ) ) : ?>
<span class="wp-block-wp-newsletter-builder-footer__social-links__item">
<a class="wp-block-wp-newsletter-builder-footer__social-links__link" href="<?php echo esc_url( $nb_instagram_url ); ?>">
<img src="/wp-content/plugins/wp-newsletter-builder/images/instagram.png" alt="Instagram" height="26" width="26" />
<a class="wp-block-wp-newsletter-builder-footer__social-links__link instagram-icon" href="<?php echo esc_url( $nb_instagram_url ); ?>">
<img
src="<?php echo esc_url( home_url() . '/wp-content/plugins/wp-newsletter-builder/images/instagram.png' ); ?>"
alt="Instagram"
height="26"
width="26"
/>
</a>
</span>
<?php endif; ?>
<?php if ( ! empty( $nb_youtube_url ) ) : ?>
<span class="wp-block-wp-newsletter-builder-footer__social-links__item">
<a class="wp-block-wp-newsletter-builder-footer__social-links__link" href="<?php echo esc_url( $nb_youtube_url ); ?>">
<img src="/wp-content/plugins/wp-newsletter-builder/images/youtube.png" alt="YouTube" height="26" width="26" />
<a class="wp-block-wp-newsletter-builder-footer__social-links__link youtube-icon" href="<?php echo esc_url( $nb_youtube_url ); ?>">
<img
src="<?php echo esc_url( home_url() . '/wp-content/plugins/wp-newsletter-builder/images/youtube.png' ); ?>"
alt="YouTube"
height="26"
width="26"
/>
</a>
</span>
<?php endif; ?>
Expand Down
22 changes: 20 additions & 2 deletions blocks/footer/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,34 @@
}

&__link {
background-color: #D62827;
border-radius: 50%;
color: #D62827;
display: inline-block;
height: 26px;
max-height: 26px;
text-decoration: underline;
transition: opacity 0.1s ease-in;
width: 26px;
}

.facebook-icon {
background-color: #1877F2;
color: #1877F2;
}

.twitter-icon {
background-color: #3CA1F2;
color: #3CA1F2;
}

.instagram-icon {
background-color: #E1306C;
color: #E1306C;
}

.youtube-icon {
background-color: #FF0000;
color: #FF0000;
}
}

.wp-block-wp-newsletter-builder-footer__logo {
Expand Down
45 changes: 45 additions & 0 deletions hooks/useEmailLists/index.ts
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;
49 changes: 49 additions & 0 deletions hooks/useNewsletterMeta/index.ts
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;
12 changes: 7 additions & 5 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
bootstrap="tests/bootstrap.php"
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
printerClass="NunoMaduro\Collision\Adapters\Phpunit\Printer"
/>
printerClass="NunoMaduro\Collision\Adapters\Phpunit\Printer">
<testsuites>
<testsuite name="wp-newsletter-builder">
<directory prefix="test-" suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
35 changes: 35 additions & 0 deletions plugins/newsletter-from-post/components/required-fields.tsx
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;
Loading

0 comments on commit 4b94306

Please sign in to comment.