diff --git a/app/common/mailgun-dao.ts b/app/common/mailgun-dao.ts deleted file mode 100644 index 314cf16..0000000 --- a/app/common/mailgun-dao.ts +++ /dev/null @@ -1,43 +0,0 @@ -export const buildMailgunDao = (apiKey: string, sendingDomain: string) => { - const api = 'https://api.mailgun.net/v3' - - return { - getMailingLists: async () => { - try { - const auth = Buffer.from(`api:${apiKey}`).toString('base64') - const endpoint = `${api}/lists/pages` - const res = await fetch(endpoint, { - method: 'GET', - headers: { - Authorization: `Basic ${auth}`, - }, - }) - - const data = await res.json() - - return { data } - } catch (error) { - console.error(error) - return null - } - }, - getMailingListVerificationStatus: async () => { - try { - debugger - const endpoint = `${api}/domains/${sendingDomain}` - const res = await fetch(endpoint, { - method: 'GET', - headers: { - Authorization: `Basic ${btoa(`api:${apiKey}`)}`, - }, - }) - - const data = await res.json() - return { data } - } catch (error) { - console.error(error) - return null - } - }, - } -} diff --git a/app/routes/_index.tsx b/app/routes/_index.tsx index 1453dcf..44d2cde 100644 --- a/app/routes/_index.tsx +++ b/app/routes/_index.tsx @@ -9,7 +9,7 @@ export const meta: MetaFunction = () => { ] } -const emailServiceProviders = ['MailChimp', 'Mailgun', 'SendGrid'] +const emailServiceProviders = ['MailChimp', 'SendGrid'] export default function Index() { const [selection, setSelection] = useState( diff --git a/app/routes/mailgun.download.tsx b/app/routes/mailgun.download.tsx deleted file mode 100644 index b1b491d..0000000 --- a/app/routes/mailgun.download.tsx +++ /dev/null @@ -1,91 +0,0 @@ -import { ActionFunctionArgs, json } from '@remix-run/node' -import { useActionData } from '@remix-run/react' -import { useState } from 'react' -import { - mailgunApiKeyKey, - mailgunSendingDomainKey, - onesignalAppIdKey, - prefsCookie, -} from '~/common/cookies' -import { buildMailgunDao } from '~/common/mailgun-dao' - -export default function MailgunMailingListSelection() { - const actionData = useActionData() - const [selection, setSelection] = useState('') - - const onSelectionChanged = (event: React.ChangeEvent) => - setSelection(event.currentTarget.value) - - const onCreateExportRecipientClicked = async () => { - const apiKey = actionData?.mailgunApiKey - const sendingDomain = actionData?.mailgunSendingDomain - - if (!apiKey || !sendingDomain) return - - const dao = buildMailgunDao(apiKey, sendingDomain) - const exportStatus = await dao.getMailingListVerificationStatus() - - console.log('Verification status', exportStatus) - } - - return ( - <> -
- - - - -
- - ) -} - -export async function action({ request }: ActionFunctionArgs) { - const cookieHeader = request.headers.get('Cookie') - const cookie = (await prefsCookie.parse(cookieHeader)) || {} - const body = await request.formData() - const onesignalAppId = body.get('onesignal-app-id') as string - const mailgunApiKey = body.get('mailgun-api-key') as string - const mailgunSendingDomain = body.get('mailgun-sending-domain') as string - cookie[mailgunApiKeyKey] = mailgunApiKey - cookie[mailgunSendingDomainKey] = mailgunSendingDomain - cookie[onesignalAppIdKey] = onesignalAppId - - const mailgunDao = buildMailgunDao(mailgunApiKey, mailgunSendingDomain) - const list = await mailgunDao.getMailingLists() - - return json( - { - mailingLists: list?.data.items || [], - mailgunSendingDomain, - mailgunApiKey, - }, - { - headers: { - 'Set-Cookie': await prefsCookie.serialize(cookie), - }, - } - ) -} diff --git a/app/routes/mailgun.tsx b/app/routes/mailgun.tsx deleted file mode 100644 index 0127add..0000000 --- a/app/routes/mailgun.tsx +++ /dev/null @@ -1,80 +0,0 @@ -import { LoaderFunctionArgs, json } from '@remix-run/node' -import { Form, Outlet, useLoaderData } from '@remix-run/react' -import { loadCookies } from '~/common/cookies' - -export default function Mailgun() { - const loaderData = useLoaderData() - - return ( - <> -
-

Mailgun

-

Authentication

-
-
- - -
-
- - -
-
- - -
- -
- -
- - ) -} - -export async function loader({ request }: LoaderFunctionArgs) { - const { mailgunApiKey, mailgunSendingDomain, onesignalAppId } = - await loadCookies(request) - - return json({ mailgunApiKey, mailgunSendingDomain, onesignalAppId }) -}