fix: emails

pull/89/head
Pierre-Louis Guhur 1 year ago
parent bfde401260
commit 461674e923

@ -12,6 +12,7 @@ const LanguageSelector = (props) => {
if (locale === 'gb') locale = 'en';
router.push('', '', {locale});
};
return (
<ReactFlagsSelect
onSelect={selectHandler}
@ -19,7 +20,7 @@ const LanguageSelector = (props) => {
// ["GB", "FR", "ES", "DE", "RU"]
['GB', 'FR']
}
selected={localeShort}
selected={localeShort == "en" ? "GB" : localeShort.toUpperCase()}
customLabels={{GB: 'English', FR: 'Francais'}}
{...props}
className="menu-flags"

@ -19,6 +19,8 @@ export const resources = {
},
} as const;
export const availableLanguages = Object.keys(resources);
export const i18n: InitOptions = {
// https://www.i18next.com/overview/configuration-options#logging

@ -56,7 +56,6 @@ const handler: Handler = async (event) => {
};
}
console.log("EVENT BODY", event.body)
const {recipients, action, locale} = JSON.parse(event.body) as RequestPayload;
if (!recipients) {

@ -1,5 +1,6 @@
import {NextRouter} from 'next/router';
import {getLocaleShort} from './utils';
import {availableLanguages} from '@functions/i18next';
export const sendInviteMails = async (
mails: Array<string>,
@ -25,10 +26,14 @@ export const sendInviteMails = async (
recipients[mails[index]] = {
urlVote: urlVotes[index],
urlResult: urlResult,
title: name,
};
});
const locale = getLocaleShort(router);
if (!availableLanguages.includes(locale)) {
throw Error(`{locale} is not available for mails`)
}
const req = await fetch('/.netlify/functions/send-emails', {
method: 'POST',
@ -38,7 +43,6 @@ export const sendInviteMails = async (
body: JSON.stringify({
action: "invite",
recipients,
title: name,
locale,
}),
});

@ -6,14 +6,10 @@ import {NextRouter} from 'next/router';
export const getLocaleShort = (router: NextRouter): string => {
if (!router.locale) {
return router.defaultLocale.substring(0, 2).toUpperCase();
return router.defaultLocale.substring(0, 2);
}
if (router.locale.startsWith("en")) {
return "GB";
}
return router.locale.substring(0, 2).toUpperCase();
return router.locale.substring(0, 2);
}

@ -2,9 +2,18 @@
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@components/*": ["components/*"],
"@styles/*": ["styles/*"],
"@services/*": ["services/*"]
"@components/*": [
"components/*"
],
"@styles/*": [
"styles/*"
],
"@services/*": [
"services/*"
],
"@functions/*": [
"functions/*"
]
},
"target": "es5",
"lib": [

Loading…
Cancel
Save