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

@ -19,6 +19,8 @@ export const resources = {
}, },
} as const; } as const;
export const availableLanguages = Object.keys(resources);
export const i18n: InitOptions = { export const i18n: InitOptions = {
// https://www.i18next.com/overview/configuration-options#logging // 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; const {recipients, action, locale} = JSON.parse(event.body) as RequestPayload;
if (!recipients) { if (!recipients) {

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

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

@ -1,36 +1,45 @@
{ {
"compilerOptions": { "compilerOptions": {
"baseUrl": "./", "baseUrl": "./",
"paths": { "paths": {
"@components/*": ["components/*"], "@components/*": [
"@styles/*": ["styles/*"], "components/*"
"@services/*": ["services/*"] ],
}, "@styles/*": [
"target": "es5", "styles/*"
"lib": [ ],
"dom", "@services/*": [
"dom.iterable", "services/*"
"esnext" ],
], "@functions/*": [
"allowJs": true, "functions/*"
"skipLibCheck": true, ]
"strict": false, },
"forceConsistentCasingInFileNames": true, "target": "es5",
"noEmit": true, "lib": [
"incremental": true, "dom",
"esModuleInterop": true, "dom.iterable",
"module": "esnext", "esnext"
"moduleResolution": "node", ],
"resolveJsonModule": true, "allowJs": true,
"isolatedModules": true, "skipLibCheck": true,
"jsx": "preserve" "strict": false,
}, "forceConsistentCasingInFileNames": true,
"include": [ "noEmit": true,
"next-env.d.ts", "incremental": true,
"**/*.ts", "esModuleInterop": true,
"**/*.tsx" "module": "esnext",
], "moduleResolution": "node",
"exclude": [ "resolveJsonModule": true,
"node_modules" "isolatedModules": true,
] "jsx": "preserve"
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
} }

Loading…
Cancel
Save