-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FW-5023 Use new contact-us API (#165)
- Loading branch information
Showing
11 changed files
with
242 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export function contactUsAdaptor({ formData }) { | ||
return { | ||
name: formData?.name || '', | ||
email: formData?.email || '', | ||
message: formData?.message || '', | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { useParams } from 'react-router-dom' | ||
import { useQuery } from '@tanstack/react-query' | ||
|
||
// FPCC | ||
import { CONTACT_US } from 'common/constants' | ||
import api from 'services/api' | ||
import { contactUsAdaptor } from 'common/dataAdaptors/contactUsAdaptor' | ||
import useMutationWithNotification from 'common/dataHooks/useMutationWithNotification' | ||
|
||
export function useContactUsEmailList() { | ||
const { sitename } = useParams() | ||
const response = useQuery( | ||
[CONTACT_US, sitename], | ||
() => api.mail.get({ sitename }), | ||
{ enabled: !!sitename }, | ||
) | ||
|
||
const emailList = response?.data?.[0]?.emailList | ||
const emailListAsString = emailList | ||
?.map((v) => Object.values(v).join('')) | ||
.join(' - ') | ||
|
||
return { ...response, emailListAsString } | ||
} | ||
|
||
export function useContactUsSendEmail() { | ||
const { sitename } = useParams() | ||
|
||
const sendMail = async (formData) => { | ||
const properties = contactUsAdaptor({ formData }) | ||
return api.mail.post({ | ||
sitename, | ||
properties, | ||
}) | ||
} | ||
|
||
const mutation = useMutationWithNotification({ | ||
mutationFn: sendMail, | ||
redirectTo: ``, | ||
queryKeyToInvalidate: [CONTACT_US, sitename], | ||
actionWord: 'sent', | ||
type: 'email', | ||
}) | ||
|
||
const onSubmit = (formData) => mutation.mutate(formData) | ||
|
||
return { onSubmit } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.