diff --git a/env.ts b/env.ts index 79869c3..9d6baff 100644 --- a/env.ts +++ b/env.ts @@ -1,12 +1,9 @@ import { defineConfig, Schema } from '@julr/vite-plugin-validate-env'; -// TODO: Integrate .env for CI and remove optional() call on required fields export default defineConfig({ APP_TITLE: Schema.string.optional(), APP_MAPBOX_ACCESS_TOKEN: Schema.string(), APP_GRAPHQL_ENDPOINT: Schema.string.optional(), APP_GOOGLE_ANALYTICS_ID: Schema.string.optional(), -}) - -// Hcaptcha -export const hCaptchaKey = process.env.REACT_APP_HCATPCHA_SITEKEY || '10000000-ffff-ffff-ffff-000000000001'; + APP_HCAPTCHA_SITEKEY: Schema.string.optional(), +}); \ No newline at end of file diff --git a/src/components/Captcha/index.tsx b/src/components/Captcha/index.tsx index e0982b0..f895d05 100644 --- a/src/components/Captcha/index.tsx +++ b/src/components/Captcha/index.tsx @@ -5,9 +5,10 @@ import { InputContainerProps, } from '@ifrc-go/ui'; +import { hCaptchaKey } from '#config'; + export type HCaptchaProps = Omit & { name: T, - siteKey: string | undefined; onChange: (value: string | undefined, name: T) => void; elementRef?: React.RefObject; }; @@ -27,9 +28,7 @@ function HCaptchaInput(props: HCaptchaProps) { inputSectionClassName, label, readOnly, - name, - siteKey, onChange, elementRef, } = props; @@ -70,11 +69,10 @@ function HCaptchaInput(props: HCaptchaProps) { inputSectionClassName={inputSectionClassName} label={label} readOnly={readOnly} - input={siteKey && ( + input={hCaptchaKey && ( {strings.appLogin} - {/* */} ; +type PartialFormFields = Partial; +type FormSchema = ObjectSchema; type FormSchemaFields = ReturnType; -const defaultFormValue: FormFields = {}; - -const usersData = [ - { - id: 1, - username: 'johndoe', - password: 'password123', - first: 'John', - last: 'Doe', - token: 'dummyToken123', - expires: '2024-12-31T23:59:59Z', - }, - { - id: 2, - username: 'janedoe', - password: 'password456', - first: 'Jane', - last: 'Doe', - token: 'dummyToken456', - expires: '2025-01-31T23:59:59Z', - }, -]; +const defaultFormValue: PartialFormFields = {}; const formSchema: FormSchema = { fields: (): FormSchemaFields => ({ - username: { + email: { required: true, requiredValidation: requiredStringCondition, }, @@ -66,13 +41,16 @@ const formSchema: FormSchema = { required: true, requiredValidation: requiredStringCondition, }, + captcha: { + required: true, + requiredValidation: requiredStringCondition, + }, }), }; // eslint-disable-next-line import/prefer-default-export export function Component() { const strings = useTranslation(i18n); - const { setUserAuth: setUser } = useContext(UserContext); const { value: formValue, setFieldValue, @@ -80,43 +58,24 @@ export function Component() { validate, } = useForm(formSchema, { value: defaultFormValue }); - const fieldError: FormFields = {}; - const [, setCaptchaToken] = useState(null); + const fieldError: PartialFormFields = {}; const handleFormSubmit = useMemo( () => createSubmitHandler( validate, setError, - () => { - const selectedUser = usersData[0]; - setUser({ - id: selectedUser.id, - username: selectedUser.username, - firstName: selectedUser.first ?? undefined, - lastName: selectedUser.last ?? undefined, - displayName: getUserName({ - first_name: selectedUser.first, - last_name: selectedUser.last, - username: selectedUser.username, - }), - token: selectedUser.token, - expires: selectedUser.expires, - }); - }, + // FIXME: Add form submission logic here + () => {}, ), - [validate, setError, setUser], + [validate, setError], ); - const handleCaptchaVerify = (token: string) => { - setCaptchaToken(token); - }; - const signupInfo = resolveToComponent( strings.loginDontHaveAccount, { signUpLink: ( {strings.loginSignUp} @@ -139,10 +98,10 @@ export function Component() { >
{strings.loginForgotUserPass} @@ -174,12 +133,13 @@ export function Component() {
diff --git a/vite.config.ts b/vite.config.ts index 97d5b48..45403fd 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -9,6 +9,7 @@ import { ValidateEnv as validateEnv } from '@julr/vite-plugin-validate-env'; import { VitePluginRadar } from 'vite-plugin-radar'; import alertHubPackage from './package.json'; +import envConfig from './env'; /* Get commit hash */ const commitHash = execSync('git rev-parse --short HEAD').toString(); @@ -35,7 +36,7 @@ export default defineConfig(({ mode }) => { reactSwc(), tsconfigPaths(), webfontDownload(), - validateEnv(), + validateEnv(envConfig), isProd ? compression() : undefined, VitePluginRadar({ analytics: {