Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Commit

Permalink
fix: threads locale through findByID (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
finkinfridom authored May 15, 2023
1 parent 1997719 commit 7531c10
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 4 additions & 0 deletions demo/src/payload.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ const colorField: Block = {

export default buildConfig({
serverURL: 'http://localhost:3000',
localization: {
locales: ['en', 'it'],
defaultLocale: 'en',
},
admin: {
user: Users.slug,
webpack: (config) => {
Expand Down
15 changes: 11 additions & 4 deletions src/collections/FormSubmissions/hooks/sendEmail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const sendEmail = async (beforeChangeData: any, formConfig: PluginConfig) => {
id: formSubmissionID
},
req: {
payload
payload,
locale
}
} = beforeChangeData;

Expand All @@ -32,6 +33,7 @@ const sendEmail = async (beforeChangeData: any, formConfig: PluginConfig) => {
const form = await payload.findByID({
id: formID,
collection: formOverrides?.slug || 'forms',
locale
});

if (form) {
Expand Down Expand Up @@ -82,9 +84,14 @@ const sendEmail = async (beforeChangeData: any, formConfig: PluginConfig) => {
try {
const emailPromise = await payload.sendEmail(email);
return emailPromise;
} catch (err) {
} catch (err: any) {
console.error(`Error while sending email to address: ${to}. Email not sent.`);
console.error(err);
if (err?.response?.body?.errors) {
const error = err.response.body.errors?.[0];
console.log('%s: %s', error?.field, error?.message);
} else {
console.log(err);
}
}
})
);
Expand All @@ -101,4 +108,4 @@ const sendEmail = async (beforeChangeData: any, formConfig: PluginConfig) => {
return data;
};

export default sendEmail;
export default sendEmail;

0 comments on commit 7531c10

Please sign in to comment.