From 45370f46c6ff1875c41f6b9b34e38045b856bf50 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Mon, 16 Jan 2023 18:36:25 +0800 Subject: [PATCH] Start to add createdAt and subscriptionCount to newsletter emails --- .../queries/useGetNewsletterEmailsQuery.tsx | 11 +- packages/web/pages/settings/emails.tsx | 418 +++++++++--------- 2 files changed, 215 insertions(+), 214 deletions(-) diff --git a/packages/web/lib/networking/queries/useGetNewsletterEmailsQuery.tsx b/packages/web/lib/networking/queries/useGetNewsletterEmailsQuery.tsx index ece0316be..92228a004 100644 --- a/packages/web/lib/networking/queries/useGetNewsletterEmailsQuery.tsx +++ b/packages/web/lib/networking/queries/useGetNewsletterEmailsQuery.tsx @@ -19,6 +19,8 @@ type NewsletterEmailsData = { export type NewsletterEmail = { id: string address: string + createdAt: Date + subscriptionCount: number confirmationCode?: string } @@ -30,6 +32,8 @@ export function useGetNewsletterEmailsQuery(): NewsletterEmailsQueryResponse { newsletterEmails { id address + createdAt + subscriptionCount confirmationCode } } @@ -46,13 +50,14 @@ export function useGetNewsletterEmailsQuery(): NewsletterEmailsQueryResponse { try { if (data) { const result = data as NewsletterEmailsResponseData - const emailAddresses = result.newsletterEmails?.newsletterEmails as NewsletterEmail[] + const emailAddresses = result.newsletterEmails + ?.newsletterEmails as NewsletterEmail[] return { isValidating, emailAddresses, revalidate: () => { mutate(undefined, true) - } + }, } } } catch (error) { @@ -62,6 +67,6 @@ export function useGetNewsletterEmailsQuery(): NewsletterEmailsQueryResponse { isValidating: false, emailAddresses: [], // eslint-disable-next-line @typescript-eslint/no-empty-function - revalidate: () => {} + revalidate: () => {}, } } diff --git a/packages/web/pages/settings/emails.tsx b/packages/web/pages/settings/emails.tsx index ce3bc53a4..d4e0aad1b 100644 --- a/packages/web/pages/settings/emails.tsx +++ b/packages/web/pages/settings/emails.tsx @@ -4,12 +4,11 @@ import { useGetNewsletterEmailsQuery } from '../../lib/networking/queries/useGet import { createNewsletterEmailMutation } from '../../lib/networking/mutations/createNewsletterEmailMutation' import { deleteNewsletterEmailMutation } from '../../lib/networking/mutations/deleteNewsletterEmailMutation' import { MoreOptionsIcon } from '../../components/elements/images/MoreOptionsIcon' -import { Info, Plus, Trash, Copy } from 'phosphor-react' +import { Plus, Trash, Copy } from 'phosphor-react' import { Dropdown, DropdownOption, } from '../../components/elements/DropdownElements' -import { TooltipWrapped } from '../../components/elements/Tooltip' import { theme, styled } from '../../components/tokens/stitches.config' import { Box, @@ -23,7 +22,6 @@ import { useCallback } from 'react' import { StyledText } from '../../components/elements/StyledText' import { applyStoredTheme } from '../../lib/themeUpdater' import { showErrorToast, showSuccessToast } from '../../lib/toastHelpers' -import Link from 'next/link' import { InfoLink } from '../../components/elements/InfoLink' enum TextType { @@ -69,7 +67,7 @@ const TableHeading = styled(Box, { width: '100%', '@md': { display: 'flex', - } + }, }) const Input = styled('input', { @@ -83,23 +81,19 @@ const Input = styled('input', { }) const CopyTextBtnWrapper = styled(Box, { - padding: '1px', background: '$grayBgActive', borderRadius: '6px', border: '1px solid rgba(0, 0, 0, 0.06)', -}) + width: '32px', + height: '32px', -const InfoIcon = styled(Info, { - marginTop: '8px', - '&:hover': { - cursor: 'pointer', - }, -}) + display: 'flex', -const TooltipStyle = { - backgroundColor: '#F9D354', - color: '#0A0806', -} + color: '#3D3D3D', + + alignItems: 'center', + justifyContent: 'center', +}) const MoreOptions = ({ onDelete }: { onDelete: () => void }) => ( { copyLink() - showSuccessToast(props.type == TextType.EmailAddress ? 'Email Address Copied' : 'Confirmation Code Copied'); + showSuccessToast( + props.type == TextType.EmailAddress + ? 'Email Address Copied' + : 'Confirmation Code Copied' + ) }, []) return ( ) } @@ -200,220 +202,214 @@ export default function EmailsPage(): JSX.Element { top: '5rem', }} /> - + - - - - - Email Addresses{' '} - - - - - - - - - EMAIL - - - - - CONFIRMATION CODE - - - - - {emailAddresses && - emailAddresses.map((email, i) => { - const { address, confirmationCode, id } = email - const isLastChild = i === emailAddresses.length - 1 - - return ( - - - Create a new email address + + + + + + + + + + Address + + + + + Created At + + + + + {emailAddresses && + emailAddresses.map((email, i) => { + const isLastChild = i === emailAddresses.length - 1 + + return ( + + - - - - - - deleteEmail(id)} /> - - - {confirmationCode && ( + + + {email.createdAt} + count: {email.subscriptionCount} + + + + + + deleteEmail(email.id)} /> + + + {email.confirmationCode && ( + + <> + + + + + + + + + )} + + + - <> - - - - - - - - - )} - - - - deleteEmail(id)} /> - - - - ) - })} - + deleteEmail(email.id)} /> + + + + ) + })} + + )