From a41b3f09a28abc509e76e261ccacf6d19cba6baf Mon Sep 17 00:00:00 2001 From: joostdecock Date: Wed, 17 May 2023 17:32:19 +0200 Subject: [PATCH] chore(shared): Move org stuff to shared to be used by the lab --- .../pages/confirm/signup/[...confirmation].mjs | 4 ++-- sites/org/pages/signup/index.mjs | 6 +++--- sites/shared/components/account/compare.mjs | 2 +- sites/shared/components/account/control.mjs | 2 +- sites/shared/components/account/imperial.mjs | 2 +- sites/shared/components/account/newsletter.mjs | 2 +- sites/shared/components/account/sets.mjs | 2 +- sites/shared/components/account/username.mjs | 2 +- .../components/buttons/email-valid-button.mjs | 2 +- .../components/buttons/flex-button-text.mjs | 2 +- .../{org => shared}/components/gdpr/details.mjs | 0 .../components/gdpr/gdpr.de.yaml | 0 .../components/gdpr/gdpr.en.yaml | 0 .../components/gdpr/gdpr.es.yaml | 0 .../components/gdpr/gdpr.fr.yaml | 0 .../components/gdpr/gdpr.nl.yaml | 0 .../components/gdpr/gdpr.uk.yaml | 0 .../components/wrappers/susi.mjs | 0 .../components/wrappers/welcome.mjs | 0 sites/shared/config/freesewing.config.mjs | 2 +- sites/shared/hooks/use-backend.mjs | 3 ++- sites/shared/utils.mjs | 17 +++++++++++++++++ 22 files changed, 33 insertions(+), 15 deletions(-) rename sites/{org => shared}/components/gdpr/details.mjs (100%) rename sites/{org => shared}/components/gdpr/gdpr.de.yaml (100%) rename sites/{org => shared}/components/gdpr/gdpr.en.yaml (100%) rename sites/{org => shared}/components/gdpr/gdpr.es.yaml (100%) rename sites/{org => shared}/components/gdpr/gdpr.fr.yaml (100%) rename sites/{org => shared}/components/gdpr/gdpr.nl.yaml (100%) rename sites/{org => shared}/components/gdpr/gdpr.uk.yaml (100%) rename sites/{org => shared}/components/wrappers/susi.mjs (100%) rename sites/{org => shared}/components/wrappers/welcome.mjs (100%) diff --git a/sites/org/pages/confirm/signup/[...confirmation].mjs b/sites/org/pages/confirm/signup/[...confirmation].mjs index 1a933c346cb..eafe96e85e1 100644 --- a/sites/org/pages/confirm/signup/[...confirmation].mjs +++ b/sites/org/pages/confirm/signup/[...confirmation].mjs @@ -12,14 +12,14 @@ import Link from 'next/link' // Components import { PageWrapper, ns as pageNs } from 'shared/components/wrappers/page.mjs' import { BareLayout, ns as layoutNs } from 'site/components/layouts/bare.mjs' -import { WelcomeWrapper } from 'site/components/wrappers/welcome.mjs' +import { WelcomeWrapper } from 'shared/components/wrappers/welcome.mjs' import { Spinner } from 'shared/components/spinner.mjs' import { Popout } from 'shared/components/popout.mjs' import { GdprProfileDetails, GdprMeasurementsDetails, ns as gdprNs, -} from 'site/components/gdpr/details.mjs' +} from 'shared/components/gdpr/details.mjs' // Translation namespaces used on this page const ns = Array.from(new Set([...pageNs, ...layoutNs, ...gdprNs, 'confirm', 'locales', 'themes'])) diff --git a/sites/org/pages/signup/index.mjs b/sites/org/pages/signup/index.mjs index 58e6a76be86..a29fe26ebf8 100644 --- a/sites/org/pages/signup/index.mjs +++ b/sites/org/pages/signup/index.mjs @@ -6,14 +6,14 @@ import { useTranslation } from 'next-i18next' import { ModalContext } from 'shared/context/modal-context.mjs' // Dependencies import { serverSideTranslations } from 'next-i18next/serverSideTranslations' -import { validateEmail, validateTld } from 'site/utils.mjs' +import { validateEmail, validateTld } from 'shared/utils.mjs' // Components import Link from 'next/link' import { PageWrapper } from 'shared/components/wrappers/page.mjs' import { BareLayout } from 'site/components/layouts/bare.mjs' -import { SusiWrapper } from 'site/components/wrappers/susi.mjs' +import { SusiWrapper } from 'shared/components/wrappers/susi.mjs' import { Robot } from 'shared/components/robot/index.mjs' -import { EmailValidButton } from 'site/components/buttons/email-valid-button.mjs' +import { EmailValidButton } from 'shared/components/buttons/email-valid-button.mjs' import { LeftIcon, HelpIcon } from 'shared/components/icons.mjs' import { ModalWrapper } from 'shared/components/wrappers/modal.mjs' diff --git a/sites/shared/components/account/compare.mjs b/sites/shared/components/account/compare.mjs index 2da61f05c94..a0d0c1013bf 100644 --- a/sites/shared/components/account/compare.mjs +++ b/sites/shared/components/account/compare.mjs @@ -9,7 +9,7 @@ import { useToast } from 'shared/hooks/use-toast.mjs' import { LoadingContext } from 'shared/context/loading-context.mjs' // Components import { Choice, Icons, welcomeSteps, BackToAccountButton } from './shared.mjs' -import { ContinueButton } from 'site/components/buttons/continue-button.mjs' +import { ContinueButton } from 'shared/components/buttons/continue-button.mjs' export const ns = ['account', 'toast'] diff --git a/sites/shared/components/account/control.mjs b/sites/shared/components/account/control.mjs index b5e2efe4c22..2f9ff4b3711 100644 --- a/sites/shared/components/account/control.mjs +++ b/sites/shared/components/account/control.mjs @@ -9,7 +9,7 @@ import { useToast } from 'shared/hooks/use-toast.mjs' import { LoadingContext } from 'shared/context/loading-context.mjs' // Components import { BackToAccountButton, Choice, Icons, welcomeSteps } from './shared.mjs' -import { ContinueButton } from 'site/components/buttons/continue-button.mjs' +import { ContinueButton } from 'shared/components/buttons/continue-button.mjs' export const ns = ['account', 'toast'] diff --git a/sites/shared/components/account/imperial.mjs b/sites/shared/components/account/imperial.mjs index ee84ac6957f..c503b6490d9 100644 --- a/sites/shared/components/account/imperial.mjs +++ b/sites/shared/components/account/imperial.mjs @@ -9,7 +9,7 @@ import { useToast } from 'shared/hooks/use-toast.mjs' import { LoadingContext } from 'shared/context/loading-context.mjs' // Components import { Choice, Icons, welcomeSteps, BackToAccountButton } from './shared.mjs' -import { ContinueButton } from 'site/components/buttons/continue-button.mjs' +import { ContinueButton } from 'shared/components/buttons/continue-button.mjs' export const ns = ['account', 'toast'] diff --git a/sites/shared/components/account/newsletter.mjs b/sites/shared/components/account/newsletter.mjs index 449cf1befed..56b433b463e 100644 --- a/sites/shared/components/account/newsletter.mjs +++ b/sites/shared/components/account/newsletter.mjs @@ -9,7 +9,7 @@ import { useToast } from 'shared/hooks/use-toast.mjs' import { LoadingContext } from 'shared/context/loading-context.mjs' // Components import { BackToAccountButton, Choice, Icons, welcomeSteps } from './shared.mjs' -import { ContinueButton } from 'site/components/buttons/continue-button.mjs' +import { ContinueButton } from 'shared/components/buttons/continue-button.mjs' export const ns = ['account', 'toast'] diff --git a/sites/shared/components/account/sets.mjs b/sites/shared/components/account/sets.mjs index be88d6b4685..084801c5b74 100644 --- a/sites/shared/components/account/sets.mjs +++ b/sites/shared/components/account/sets.mjs @@ -6,7 +6,7 @@ import { CopyToClipboard } from 'react-copy-to-clipboard' import orderBy from 'lodash.orderby' import { measurements, isDegreeMeasurement } from 'config/measurements.mjs' import { measurementAsMm, formatMm } from 'shared/utils.mjs' -import { measurements as designMeasurements } from 'site/prebuild/design-measurements.mjs' +import { measurements as designMeasurements } from 'shared/prebuild/data/design-measurements.mjs' import { freeSewingConfig as conf } from 'shared/config/freesewing.config.mjs' // Hooks import { useDropzone } from 'react-dropzone' diff --git a/sites/shared/components/account/username.mjs b/sites/shared/components/account/username.mjs index 0d7e6f2cc5c..6040e52bc45 100644 --- a/sites/shared/components/account/username.mjs +++ b/sites/shared/components/account/username.mjs @@ -11,7 +11,7 @@ import { LoadingContext } from 'shared/context/loading-context.mjs' import { Spinner } from 'shared/components/spinner.mjs' import { Icons, welcomeSteps, BackToAccountButton } from './shared.mjs' import { OkIcon, NoIcon } from 'shared/components/icons.mjs' -import { ContinueButton } from 'site/components/buttons/continue-button.mjs' +import { ContinueButton } from 'shared/components/buttons/continue-button.mjs' export const ns = ['account', 'toast'] diff --git a/sites/shared/components/buttons/email-valid-button.mjs b/sites/shared/components/buttons/email-valid-button.mjs index 25b2b7492d7..197f182a483 100644 --- a/sites/shared/components/buttons/email-valid-button.mjs +++ b/sites/shared/components/buttons/email-valid-button.mjs @@ -1,5 +1,5 @@ import { useContext } from 'react' -import { validateEmail, validateTld } from 'site/utils.mjs' +import { validateEmail, validateTld } from 'shared/utils.mjs' import { Spinner } from 'shared/components/spinner.mjs' import { useTranslation } from 'next-i18next' import { EmailIcon, RightIcon, WarningIcon } from 'shared/components/icons.mjs' diff --git a/sites/shared/components/buttons/flex-button-text.mjs b/sites/shared/components/buttons/flex-button-text.mjs index 89b6f621399..1e1cb1a5812 100644 --- a/sites/shared/components/buttons/flex-button-text.mjs +++ b/sites/shared/components/buttons/flex-button-text.mjs @@ -1,4 +1,4 @@ -import { validateEmail, validateTld } from 'site/utils.mjs' +import { validateEmail, validateTld } from 'shared/utils.mjs' import { Spinner } from 'shared/components/spinner.mjs' import { useTranslation } from 'next-i18next' import { EmailIcon, RightIcon, WarningIcon } from 'shared/components/icons.mjs' diff --git a/sites/org/components/gdpr/details.mjs b/sites/shared/components/gdpr/details.mjs similarity index 100% rename from sites/org/components/gdpr/details.mjs rename to sites/shared/components/gdpr/details.mjs diff --git a/sites/org/components/gdpr/gdpr.de.yaml b/sites/shared/components/gdpr/gdpr.de.yaml similarity index 100% rename from sites/org/components/gdpr/gdpr.de.yaml rename to sites/shared/components/gdpr/gdpr.de.yaml diff --git a/sites/org/components/gdpr/gdpr.en.yaml b/sites/shared/components/gdpr/gdpr.en.yaml similarity index 100% rename from sites/org/components/gdpr/gdpr.en.yaml rename to sites/shared/components/gdpr/gdpr.en.yaml diff --git a/sites/org/components/gdpr/gdpr.es.yaml b/sites/shared/components/gdpr/gdpr.es.yaml similarity index 100% rename from sites/org/components/gdpr/gdpr.es.yaml rename to sites/shared/components/gdpr/gdpr.es.yaml diff --git a/sites/org/components/gdpr/gdpr.fr.yaml b/sites/shared/components/gdpr/gdpr.fr.yaml similarity index 100% rename from sites/org/components/gdpr/gdpr.fr.yaml rename to sites/shared/components/gdpr/gdpr.fr.yaml diff --git a/sites/org/components/gdpr/gdpr.nl.yaml b/sites/shared/components/gdpr/gdpr.nl.yaml similarity index 100% rename from sites/org/components/gdpr/gdpr.nl.yaml rename to sites/shared/components/gdpr/gdpr.nl.yaml diff --git a/sites/org/components/gdpr/gdpr.uk.yaml b/sites/shared/components/gdpr/gdpr.uk.yaml similarity index 100% rename from sites/org/components/gdpr/gdpr.uk.yaml rename to sites/shared/components/gdpr/gdpr.uk.yaml diff --git a/sites/org/components/wrappers/susi.mjs b/sites/shared/components/wrappers/susi.mjs similarity index 100% rename from sites/org/components/wrappers/susi.mjs rename to sites/shared/components/wrappers/susi.mjs diff --git a/sites/org/components/wrappers/welcome.mjs b/sites/shared/components/wrappers/welcome.mjs similarity index 100% rename from sites/org/components/wrappers/welcome.mjs rename to sites/shared/components/wrappers/welcome.mjs diff --git a/sites/shared/config/freesewing.config.mjs b/sites/shared/config/freesewing.config.mjs index dc0f7a5647c..c0e637925c9 100644 --- a/sites/shared/config/freesewing.config.mjs +++ b/sites/shared/config/freesewing.config.mjs @@ -2,7 +2,7 @@ import { social } from 'config/social.mjs' export const freeSewingConfig = { monorepo: 'https://github.com/freesewing/freesewing', - backend: process.env.NEXT_PUBLIC_BACKEND, + backend: process.env.NEXT_PUBLIC_BACKEND || 'https://backend3.freesewing.org', maxWidth: 2800, account: { fields: { diff --git a/sites/shared/hooks/use-backend.mjs b/sites/shared/hooks/use-backend.mjs index bdc4f534f3f..00e46f64708 100644 --- a/sites/shared/hooks/use-backend.mjs +++ b/sites/shared/hooks/use-backend.mjs @@ -1,11 +1,12 @@ import axios from 'axios' import process from 'process' +import { freeSewingConfig } from 'shared/config/freesewing.config.mjs' /* * Helper methods to interact with the FreeSewing backend */ const apiHandler = axios.create({ - baseURL: process.env.NEXT_PUBLIC_BACKEND || 'https://backend.freesewing.org', + baseURL: freeSewingConfig.backend, timeout: 3000, }) diff --git a/sites/shared/utils.mjs b/sites/shared/utils.mjs index 099cb3c07ec..8e633c85c24 100644 --- a/sites/shared/utils.mjs +++ b/sites/shared/utils.mjs @@ -1,3 +1,4 @@ +import tlds from 'tlds/index.json' assert { type: 'json' } import get from 'lodash.get' import set from 'lodash.set' import orderBy from 'lodash.orderby' @@ -222,3 +223,19 @@ export const objUpdate = (obj = {}, path, val = 'unset') => { return obj } + +/** Validates an email address for correct syntax */ +export const validateEmail = (email) => { + /* eslint-disable */ + const re = + /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ + /* eslint-enable */ + return re.test(email) +} + +/** Validates the top level domain (TLT) for an email address */ +export const validateTld = (email) => { + const tld = email.split('@').pop().split('.').pop().toLowerCase() + if (tlds.indexOf(tld) === -1) return tld + else return true +}