ActiveCampaignConfig.js
5 years ago
ChooseProvider.js
2 months ago
FluentCRMConfig.js
3 weeks ago
MailchimpConfig.js
5 years ago
MailerLiteConfig.js
5 years ago
WebhooksConfig.js
3 years ago
YoutubeChannelId.js
1 month ago
YoutubeChannelId.scss
1 month ago
MailchimpConfig.js
90 lines
| 1 | /** |
| 2 | * WordPress dependencies |
| 3 | */ |
| 4 | const { __ } = wp.i18n; |
| 5 | const { SelectControl, TextControl, Notice } = wp.components; |
| 6 | const { useEffect, useState } = wp.element; |
| 7 | import LoadSelect from "../../components/LoadSelect"; |
| 8 | |
| 9 | export default ({ options, updateEmailState }) => { |
| 10 | const [fetching, setFetching] = useState(false); |
| 11 | const [lists, setLists] = useState([ |
| 12 | { value: null, label: __("Choose an audience", "presto-player") }, |
| 13 | ]); |
| 14 | const [error, setError] = useState(""); |
| 15 | |
| 16 | const fetchLists = async () => { |
| 17 | setFetching(true); |
| 18 | try { |
| 19 | const fetched = await wp.apiFetch({ |
| 20 | path: "presto-player/v1/mailchimp/lists", |
| 21 | }); |
| 22 | |
| 23 | let listOptions = lists; |
| 24 | (fetched || []).forEach((list) => { |
| 25 | listOptions = [ |
| 26 | ...listOptions, |
| 27 | ...[ |
| 28 | { |
| 29 | value: list.id, |
| 30 | label: list.name, |
| 31 | }, |
| 32 | ], |
| 33 | ]; |
| 34 | }); |
| 35 | setLists(listOptions); |
| 36 | } catch (e) { |
| 37 | if (e?.message) { |
| 38 | setError(e.message); |
| 39 | } |
| 40 | } finally { |
| 41 | setFetching(false); |
| 42 | } |
| 43 | }; |
| 44 | |
| 45 | useEffect(() => { |
| 46 | fetchLists(); |
| 47 | }, []); |
| 48 | |
| 49 | if (fetching) { |
| 50 | return ( |
| 51 | <div> |
| 52 | <LoadSelect /> |
| 53 | <LoadSelect /> |
| 54 | </div> |
| 55 | ); |
| 56 | } |
| 57 | |
| 58 | if (error) { |
| 59 | return ( |
| 60 | <Notice className="presto-notice" status="error" isDismissible={false}> |
| 61 | {error} |
| 62 | </Notice> |
| 63 | ); |
| 64 | } |
| 65 | |
| 66 | return ( |
| 67 | <div> |
| 68 | <SelectControl |
| 69 | label={__("Choose an audience", "presto-player")} |
| 70 | value={options?.provider_list} |
| 71 | options={lists} |
| 72 | onChange={(provider_list) => updateEmailState({ provider_list })} |
| 73 | /> |
| 74 | <TextControl |
| 75 | label={__("Tag", "presto-player")} |
| 76 | help={ |
| 77 | <p> |
| 78 | {__( |
| 79 | "Give this contact an optional tag when they are added to the list.", |
| 80 | "presto-player" |
| 81 | )} |
| 82 | </p> |
| 83 | } |
| 84 | value={options?.provider_tag} |
| 85 | onChange={(provider_tag) => updateEmailState({ provider_tag })} |
| 86 | /> |
| 87 | </div> |
| 88 | ); |
| 89 | }; |
| 90 |