better errors and notifications

This commit is contained in:
Willi 2023-02-27 17:10:42 -05:00
parent 379fe6600b
commit e6e871a94b
4 changed files with 42 additions and 41 deletions

View File

@ -55,11 +55,7 @@ const CustomForm = ({ data }: FormProps) => {
message: text,
inquiry: selectedOption.value
})
})
.then(() => {
setNotification("Thanks! We'll be in touch soon.")
})
.catch((err) => console.error(err))
}).catch((err) => console.error(err))
}
const handleSubmitForm = useCallback(
@ -99,11 +95,7 @@ const CustomForm = ({ data }: FormProps) => {
message: text,
inquiry: selectedOption.value
})
})
.then(() => {
setNotification("Thanks! We'll be in touch soon.")
})
.catch((err) => console.error(err))
}).catch((err) => console.error(err))
setIsSending(false)
setIsFormSent(true)

View File

@ -74,11 +74,12 @@ const CustomForm = ({ data }: FormProps) => {
inquiry: selectedOption.value,
gReCaptchaToken: gReCaptchaToken
})
}).catch((err) => {
console.error(err)
setNotification(
'Sorry, we couldnt send your message. Please try again later.'
)
})
.then(() => {
setNotification("Thanks! We'll be in touch soon.")
})
.catch((err) => console.error(err))
}
const handleSubmitForm = useCallback(
@ -122,11 +123,12 @@ const CustomForm = ({ data }: FormProps) => {
message: text,
inquiry: selectedOption.value
})
}).catch((err) => {
console.error(err)
setNotification(
'Sorry, we couldnt send your message. Please try again later.'
)
})
.then(() => {
setNotification("Thanks! We'll be in touch soon.")
})
.catch((err) => console.error(err))
setIsSending(false)
setIsFormSent(true)

View File

@ -12,14 +12,17 @@ export default async function handler(req, res) {
const message = body.message
// eslint-disable-next-line no-console
const response = await mailchimp.lists.addListMember('5b23f4626d', {
email_address: email, // MERGE0
status: 'subscribed',
merge_fields: {
INQUIRY: inquiry, // MERGE3
MESSAGE: message // MERGE4
}
})
res.status(200).json({ response })
try {
const response = await mailchimp.lists.addListMember('5b23f4626d', {
email_address: email, // MERGE0
status: 'subscribed',
merge_fields: {
INQUIRY: inquiry, // MERGE3
MESSAGE: message // MERGE4
}
})
res.status(200).json({ response })
} catch (err) {
res.status(500).json(err)
}
}

View File

@ -15,17 +15,21 @@ export default async function handler(req, res) {
const role = body.role
const company = body.company
const jurisdiction = body.jurisdiction // JURIS
const response = await mailchimp.lists.addListMember('0c1f26e807', {
email_address: email, // MERGE0
status: 'subscribed',
merge_fields: {
NAME: name, // MERGE1
ROLE: role, // MERGE2
COMPANY: company, // MERGE3
JURIS: jurisdiction, // MERGE4
INQUIRY: inquiry, // MERGE5
MESSAGE: message // MERGE6
}
})
res.status(200).json({ name: response })
try {
await mailchimp.lists.addListMember('0c1f26e807', {
email_address: email, // MERGE0
status: 'subscribed',
merge_fields: {
NAME: name, // MERGE1
ROLE: role, // MERGE2
COMPANY: company, // MERGE3
JURIS: jurisdiction, // MERGE4
INQUIRY: inquiry, // MERGE5
MESSAGE: message // MERGE6
}
})
res.status(200)
} catch (err) {
res.status(500).json(err)
}
}