From e70c0f5dee990d2694a17b019267d76e572383ab Mon Sep 17 00:00:00 2001 From: Siddharth Date: Sun, 22 Oct 2023 19:20:34 +0530 Subject: [PATCH] fix: error handling, dark mode, consent bug fixes --- .../button/primary-button-component.tsx | 6 +- .../button/secondary-button-component.tsx | 2 +- .../components/captcha-challenge/index.tsx | 47 ++++-- .../app/components/card/card.module.css | 6 +- .../app/components/input-component.tsx | 32 +++- apps/consent/app/components/logo/index.tsx | 59 +++++++- .../app/components/main-container/index.tsx | 4 +- .../app/components/next-themes-provider.tsx | 11 ++ .../scope-item/scope-item.module.css | 4 +- apps/consent/app/components/select.tsx | 47 ++++++ apps/consent/app/components/separator.tsx | 6 +- .../verification-code-form.tsx | 91 ++++++----- apps/consent/app/consent/page.tsx | 13 +- apps/consent/app/error-handler.ts | 25 +++ apps/consent/app/globals.css | 18 ++- apps/consent/app/layout.tsx | 43 +++--- apps/consent/app/login/email-login-form.tsx | 90 +++++++++++ .../app/login/email-login-server-action.ts | 86 +++++++++++ apps/consent/app/login/page.tsx | 143 +----------------- apps/consent/app/login/phone/form.tsx | 34 +++-- .../app/login/phone/phone-input-styles.css | 25 +-- .../consent/app/login/phone/server-actions.ts | 53 ++++--- apps/consent/app/login/verification/form.tsx | 3 + .../app/login/verification/server-actions.ts | 16 +- apps/consent/env.ts | 26 ++-- apps/consent/package.json | 1 + apps/consent/services/galoy-auth/index.ts | 2 + apps/dashboard/.env | 2 +- pnpm-lock.yaml | 15 ++ 29 files changed, 593 insertions(+), 317 deletions(-) create mode 100644 apps/consent/app/components/next-themes-provider.tsx create mode 100644 apps/consent/app/components/select.tsx create mode 100644 apps/consent/app/error-handler.ts create mode 100644 apps/consent/app/login/email-login-form.tsx create mode 100644 apps/consent/app/login/email-login-server-action.ts diff --git a/apps/consent/app/components/button/primary-button-component.tsx b/apps/consent/app/components/button/primary-button-component.tsx index 80c95b1b7f3..7c1d4c88190 100644 --- a/apps/consent/app/components/button/primary-button-component.tsx +++ b/apps/consent/app/components/button/primary-button-component.tsx @@ -23,8 +23,10 @@ const PrimaryButton: React.FC = ({ disabled={loadOrDisable} {...buttonProps} className={`flex-1 ${ - !loadOrDisable ? "bg-orange-500" : "bg-orange-600" - } text-white p-2 rounded-lg text-sm hover:bg-orange-600`} + !loadOrDisable + ? "bg-[var(--primaryButtonBackground)]" + : "bg-[var(--primaryButtonBackground)]" + } text-[var(--primaryButtonFont)] p-2 rounded-lg text-sm hover:bg-[var(--primaryButtonBackground)]`} > {loadOrDisable ? : children} diff --git a/apps/consent/app/components/button/secondary-button-component.tsx b/apps/consent/app/components/button/secondary-button-component.tsx index d6b5f37a908..54261621e28 100644 --- a/apps/consent/app/components/button/secondary-button-component.tsx +++ b/apps/consent/app/components/button/secondary-button-component.tsx @@ -20,7 +20,7 @@ const SecondaryButton: React.FC = ({ diff --git a/apps/consent/app/components/captcha-challenge/index.tsx b/apps/consent/app/components/captcha-challenge/index.tsx index ed2956fbe7e..5cce684df26 100644 --- a/apps/consent/app/components/captcha-challenge/index.tsx +++ b/apps/consent/app/components/captcha-challenge/index.tsx @@ -1,8 +1,15 @@ "use client"; import { sendPhoneCode } from "@/app/login/phone/server-actions"; +import { env } from "@/env"; import { memo, useCallback, useEffect } from "react"; import { toast } from "react-toastify"; +declare global { + interface Window { + initGeetest: (options: any, callback: (captchaObj: any) => void) => void; + } +} + const CaptchaChallengeComponent: React.FC<{ id: string; challenge: string; @@ -10,8 +17,21 @@ const CaptchaChallengeComponent: React.FC<{ login_challenge: string; phone: string; remember: string; + channel: string ; }; }> = ({ id, challenge, formData }) => { + const sendMockData = async () => { + const mockCaptchaResult = { + geetest_challenge: "mockChallenge", + geetest_validate: "mockValidate", + geetest_seccode: "mockSecCode", + }; + const res = await sendPhoneCode(mockCaptchaResult, formData); + if (res?.error) { + toast.error(res.message); + } + }; + const captchaHandler = useCallback( (captchaObj: any) => { const onSuccess = async () => { @@ -35,18 +55,21 @@ const CaptchaChallengeComponent: React.FC<{ ); useEffect(() => { - // @ts-ignore - window.initGeetest( - { - gt: id, - challenge: challenge, - offline: false, - new_captcha: true, - product: "bind", - lang: "en", - }, - captchaHandler - ); + if (env.NODE_ENV === "development") { + sendMockData(); + } else { + window.initGeetest( + { + gt: id, + challenge: challenge, + offline: false, + new_captcha: true, + product: "bind", + lang: "en", + }, + captchaHandler + ); + } }, [captchaHandler, id, challenge]); return
; diff --git a/apps/consent/app/components/card/card.module.css b/apps/consent/app/components/card/card.module.css index 7e98888271e..bcb2de357bb 100644 --- a/apps/consent/app/components/card/card.module.css +++ b/apps/consent/app/components/card/card.module.css @@ -6,11 +6,9 @@ @media (min-width: 768px) { .card { - background-color: white; + background-color: var(--backgroundColor); border-radius: 0.5rem; - box-shadow: - rgba(0, 0, 0, 0.144) 0px 1px 3px 0px, - rgba(27, 31, 35, 0.144) 0px 0px 0px 1px; + box-shadow: var(--shadow); width: auto; margin: auto; width: 25em; diff --git a/apps/consent/app/components/input-component.tsx b/apps/consent/app/components/input-component.tsx index 52391564224..d5b8ea132f4 100644 --- a/apps/consent/app/components/input-component.tsx +++ b/apps/consent/app/components/input-component.tsx @@ -1,21 +1,37 @@ -import React, { InputHTMLAttributes } from "react" +import React, { InputHTMLAttributes } from "react"; interface InputProps extends InputHTMLAttributes { - label?: string - id: string + label?: string; + id: string; } const InputComponent: React.FC = ({ label, id, ...inputProps }) => { return (
{label ? ( -
- ) -} + ); +}; -export default InputComponent +export default InputComponent; diff --git a/apps/consent/app/components/logo/index.tsx b/apps/consent/app/components/logo/index.tsx index 9c860ca6af9..7b53b6023c5 100644 --- a/apps/consent/app/components/logo/index.tsx +++ b/apps/consent/app/components/logo/index.tsx @@ -1,11 +1,62 @@ import React from "react"; -import Image from "next/image"; const Logo: React.FC = () => { return ( -
- Galoy -
+ + + + + + + + + + ); }; diff --git a/apps/consent/app/components/main-container/index.tsx b/apps/consent/app/components/main-container/index.tsx index 77fc3191663..419331ec098 100644 --- a/apps/consent/app/components/main-container/index.tsx +++ b/apps/consent/app/components/main-container/index.tsx @@ -6,10 +6,10 @@ interface MainContentProps { const MainContent: React.FC = ({ children }) => { return ( -
+
{children}
- ) + ); } export default MainContent diff --git a/apps/consent/app/components/next-themes-provider.tsx b/apps/consent/app/components/next-themes-provider.tsx new file mode 100644 index 00000000000..cf140e5fde1 --- /dev/null +++ b/apps/consent/app/components/next-themes-provider.tsx @@ -0,0 +1,11 @@ +"use client"; +import React, { ReactNode } from "react"; +import { ThemeProvider } from "next-themes"; + +interface Props { + children: ReactNode; +} + +export default function Theme({ children }: Props) { + return {children}; +} \ No newline at end of file diff --git a/apps/consent/app/components/scope-item/scope-item.module.css b/apps/consent/app/components/scope-item/scope-item.module.css index 66e3bc0922b..f355cf0550a 100644 --- a/apps/consent/app/components/scope-item/scope-item.module.css +++ b/apps/consent/app/components/scope-item/scope-item.module.css @@ -8,12 +8,14 @@ border-radius: 0.5rem; margin-bottom: 0.5em; position: relative; + color: var(--inputColor); + background-color: var(--inputBackground); } .custom_label { position: relative; cursor: pointer; - flex-grow: 1; + flex-grow: 1; } .text-gray-700 { diff --git a/apps/consent/app/components/select.tsx b/apps/consent/app/components/select.tsx new file mode 100644 index 00000000000..98ec83d115b --- /dev/null +++ b/apps/consent/app/components/select.tsx @@ -0,0 +1,47 @@ +import React, { SelectHTMLAttributes } from "react"; + +interface SelectProps extends SelectHTMLAttributes { + label?: string; + id: string; + options: string[]; +} + +const SelectComponent: React.FC = ({ + label, + id, + options, + ...selectProps +}) => { + return ( +
+ {label ? ( + + ) : null} + +
+ ); +}; + +export default SelectComponent; diff --git a/apps/consent/app/components/separator.tsx b/apps/consent/app/components/separator.tsx index acb3af0da74..c4e79e9b3aa 100644 --- a/apps/consent/app/components/separator.tsx +++ b/apps/consent/app/components/separator.tsx @@ -8,13 +8,13 @@ const Separator: React.FC = ({ children }) => { return (
-
+
- + {children}
-
+
); diff --git a/apps/consent/app/components/varification-components/verification-code-form.tsx b/apps/consent/app/components/varification-components/verification-code-form.tsx index 5d1ca1d153f..fd88d643efb 100644 --- a/apps/consent/app/components/varification-components/verification-code-form.tsx +++ b/apps/consent/app/components/varification-components/verification-code-form.tsx @@ -1,4 +1,5 @@ -import React from "react"; +"use client"; +import React, { useState, useEffect } from "react"; import InputComponent from "@/app/components/input-component"; import PrimaryButtonComponent from "@/app/components/button/primary-button-component"; @@ -18,41 +19,59 @@ const VerificationCodeForm: React.FC = ({ remember, loginType, value, -}) => ( - <> -

- Enter Verification Code -

-
- - - - - -
-

- The code was sent to your {loginType}{" "} -

- {value} -
- - { + const [code, setCode] = useState(""); + + const handleChange = (e: React.ChangeEvent) => { + if (e.target.value.length <= 6) { + setCode(e.target.value); + } + }; + + useEffect(() => { + if (code.length === 6 && !isNaN(Number(code))) { + document.forms[0].requestSubmit(); + } + }, [code]); + + return ( + <> +

- Submit - - - -); + Enter Verification Code +

+
+ + + + + +
+

+ The code was sent to your {loginType}{" "} +

+ {value} +
+ + + Submit + + + + ); +}; export default VerificationCodeForm; diff --git a/apps/consent/app/consent/page.tsx b/apps/consent/app/consent/page.tsx index 3a92f847195..bea85cdf5f8 100644 --- a/apps/consent/app/consent/page.tsx +++ b/apps/consent/app/consent/page.tsx @@ -111,7 +111,7 @@ const Consent = async ({ searchParams }: { searchParams: ConsentProps }) => { value={consent_challenge} /> -

+

Application{" "} {client.client_name || client.client_id} wants access resources on your behalf and to: @@ -121,13 +121,10 @@ const Consent = async ({ searchParams }: { searchParams: ConsentProps }) => { ))} -

+

Do you want to be asked next time when this application wants to - access your data? -

-

- The application will not be able to ask for more permissions without - your consent. + access your data? The application will not be able to ask for more + permissions without your consent.

    {client.policy_uri && ( @@ -159,7 +156,7 @@ const Consent = async ({ searchParams }: { searchParams: ConsentProps }) => { value="1" className="mr-2" /> -