diff --git a/packages/web/lib/networking/mutations/markEmailAsItemMutation.ts b/packages/web/lib/networking/mutations/markEmailAsItemMutation.ts new file mode 100644 index 000000000..9f8fb8d9b --- /dev/null +++ b/packages/web/lib/networking/mutations/markEmailAsItemMutation.ts @@ -0,0 +1,35 @@ +import { gqlFetcher } from '../networkHelpers' + +type MarkEmailAsItemDataResponseData = { + markEmailAsItem?: MarkEmailAsItemData +} + +type MarkEmailAsItemData = { + success: Boolean + errorCodes?: unknown[] +} + +export async function markEmailAsItemMutation( + recentEmailId: String +): Promise { + const mutation = ` + mutation MarkRecentEmailAsItem($recentEmailId: ID!) { + markEmailAsItem(recentEmailId:$recentEmailId) { + ... on MarkEmailAsItemError { + errorCodes + } + ... on MarkEmailAsItemSuccess { + success + } + } + }` + + const data = await gqlFetcher(mutation, { recentEmailId }) + console.log('recentEmailId: ', data) + const output = data as MarkEmailAsItemDataResponseData | undefined + const error = output?.markEmailAsItem?.errorCodes?.find(() => true) + console.log('error: ', error) + if (error) { + throw error + } +} diff --git a/packages/web/pages/settings/emails/index.tsx b/packages/web/pages/settings/emails/index.tsx index 4f064d53e..c6381f007 100644 --- a/packages/web/pages/settings/emails/index.tsx +++ b/packages/web/pages/settings/emails/index.tsx @@ -118,7 +118,6 @@ export default function EmailsPage(): JSX.Element { <> { + action={async () => { console.log('marking as email', recentEmail) + showSuccessToast('Marking email as article') + try { + await markEmailAsItemMutation(recentEmail.id) + } catch (err) { + console.log('error marking as article: ', err) + showErrorToast('Error marking item as article') + return + } + showSuccessToast('Email added to library') }} />