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

fix(locale): added 'locale' information in payload.findByID #31

Merged
merged 8 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;