From 64270b45661eaa0cdcfb00ca57a4f30c25259f3b Mon Sep 17 00:00:00 2001 From: rathanak-0080 <148197234+rathanak-0080@users.noreply.github.com> Date: Wed, 13 Dec 2023 19:29:11 +0700 Subject: [PATCH] update signup ui env (#41) Co-authored-by: Sreang Rathanak Signed-off-by: Sreang Rathanak --- .../src/main/resources/application-default.properties | 4 +++- .../signup/controllers/SignUpSettingsControllerTest.java | 1 + .../src/test/resources/application-test.properties | 3 ++- signup-ui/.env.example | 2 -- .../components/AccountRegistrationStatusLayout.tsx | 4 +++- signup-ui/src/pages/SignUpPage/Phone/Phone.tsx | 3 +-- signup-ui/src/pages/SignUpPage/PhoneStatus/PhoneStatus.tsx | 4 +++- signup-ui/src/pages/SignUpPage/SignUpPopover.tsx | 4 +++- signup-ui/src/services/api.service.ts | 5 ++++- signup-ui/src/typings/types.ts | 1 + signup-ui/src/utils/link.ts | 6 +++--- 11 files changed, 24 insertions(+), 13 deletions(-) diff --git a/signup-service/src/main/resources/application-default.properties b/signup-service/src/main/resources/application-default.properties index 3362eb7d..bd3535ec 100644 --- a/signup-service/src/main/resources/application-default.properties +++ b/signup-service/src/main/resources/application-default.properties @@ -106,8 +106,10 @@ mosip.signup.ui.config.key-values={\ 'fullname.pattern': '${mosip.signup.fullname.pattern}', \ 'status.request.delay': ${mosip.signup.status.request.delay}, \ 'status.request.limit': ${mosip.signup.status.request.limit}, \ -'popup.timeout': 10 \ +'popup.timeout': 10, \ +'signin.redirect-url': 'https://esignet.camdgc-dev.mosip.net/authorize' \ } + ## ----------------------------- SMS-message ----------------------------------------------------------------------------- mosip.signup.sms-notification-template.send-otp.khm=ប្រើ {challenge} ដើម្បីផ្ទៀងផ្ទាត់គណនី KhID របស់អ្នក។ mosip.signup.sms-notification-template.send-otp.eng=Use {challenge} to verify your KhID account. diff --git a/signup-service/src/test/java/io/mosip/signup/controllers/SignUpSettingsControllerTest.java b/signup-service/src/test/java/io/mosip/signup/controllers/SignUpSettingsControllerTest.java index 31698eef..406e5530 100644 --- a/signup-service/src/test/java/io/mosip/signup/controllers/SignUpSettingsControllerTest.java +++ b/signup-service/src/test/java/io/mosip/signup/controllers/SignUpSettingsControllerTest.java @@ -42,6 +42,7 @@ public void getSignupSettings_thenPass () throws Exception { .andExpect(jsonPath("$['response']['configs']['fullname.pattern']").value(".*")) .andExpect(jsonPath("$['response']['configs']['status.request.delay']").value(20)) .andExpect(jsonPath("$['response']['configs']['status.request.limit']").value(10)) + .andExpect(jsonPath("$['response']['configs']['signin.redirect-url']").value("https://esignet.camdgc-dev.mosip.net/authorize")) .andExpect(jsonPath("$.errors").isEmpty()); } } diff --git a/signup-service/src/test/resources/application-test.properties b/signup-service/src/test/resources/application-test.properties index b80d75b4..c65e6c2d 100644 --- a/signup-service/src/test/resources/application-test.properties +++ b/signup-service/src/test/resources/application-test.properties @@ -123,7 +123,8 @@ mosip.signup.ui.config.key-values={\ 'resend.delay': '${mosip.signup.challenge.resend-delay}', \ 'fullname.pattern': '${mosip.signup.fullname.pattern}', \ 'status.request.delay': '${mosip.signup.status.request.delay}', \ -'status.request.limit': '${mosip.signup.status.request.limit}' \ +'status.request.limit': '${mosip.signup.status.request.limit}', \ +'signin.redirect-url': 'https://esignet.camdgc-dev.mosip.net/authorize' \ } ## ----------------------------- SMS-message ----------------------------------------------------------------------------- mosip.signup.otp-registration.sms.khm=ប្រើ XXXXXX ដើម្បីផ្ទៀងផ្ទាត់គណនី KhID របស់អ្នក។ diff --git a/signup-ui/.env.example b/signup-ui/.env.example index 96126858..80a0115c 100644 --- a/signup-ui/.env.example +++ b/signup-ui/.env.example @@ -1,3 +1 @@ REACT_APP_API_BASE_URL="http://localhost:8088/v1/signup" -REACT_APP_REDIRECT_SIGN_IN_URL="https://esignet.camdgc-dev.mosip.net/authorize" -REACT_APP_REDIRECT_SIGN_UP_URL="http://localhost:3000/signup" diff --git a/signup-ui/src/pages/SignUpPage/AccountRegistrationStatus/components/AccountRegistrationStatusLayout.tsx b/signup-ui/src/pages/SignUpPage/AccountRegistrationStatus/components/AccountRegistrationStatusLayout.tsx index 8b3f5003..a2f00dc9 100644 --- a/signup-ui/src/pages/SignUpPage/AccountRegistrationStatus/components/AccountRegistrationStatusLayout.tsx +++ b/signup-ui/src/pages/SignUpPage/AccountRegistrationStatus/components/AccountRegistrationStatusLayout.tsx @@ -5,6 +5,7 @@ import { ReactComponent as FailedIconSvg } from "~assets/svg/failed-icon.svg"; import { ReactComponent as SuccessIconSvg } from "~assets/svg/success-icon.svg"; import { Button } from "~components/ui/button"; import { Step, StepContent } from "~components/ui/step"; +import { useSettings } from "~pages/SignUpPage/queries"; import { getSignInRedirectURL } from "~utils/link"; interface AccountRegistrationStatusLayoutProps { @@ -17,11 +18,12 @@ export const AccountRegistrationStatusLayout = ({ message, }: AccountRegistrationStatusLayoutProps) => { const { t } = useTranslation(); + const { data: settings } = useSettings(); const { hash: fromSignInHash } = useLocation(); const handleAction = (e: any) => { e.preventDefault(); - window.location.href = getSignInRedirectURL(fromSignInHash); + window.location.href = getSignInRedirectURL(settings?.response.configs["signin.redirect-url"], fromSignInHash); }; return ( diff --git a/signup-ui/src/pages/SignUpPage/Phone/Phone.tsx b/signup-ui/src/pages/SignUpPage/Phone/Phone.tsx index f5f4e274..1ecf0d8e 100644 --- a/signup-ui/src/pages/SignUpPage/Phone/Phone.tsx +++ b/signup-ui/src/pages/SignUpPage/Phone/Phone.tsx @@ -46,7 +46,6 @@ interface PhoneProps { } export const Phone = ({ settings, methods }: PhoneProps) => { const { i18n, t } = useTranslation(); - const { setStep, setCriticalError } = useSignUpStore( useCallback( (state) => ({ @@ -137,7 +136,7 @@ export const Phone = ({ settings, methods }: PhoneProps) => { {!!fromSignInHash && ( diff --git a/signup-ui/src/pages/SignUpPage/PhoneStatus/PhoneStatus.tsx b/signup-ui/src/pages/SignUpPage/PhoneStatus/PhoneStatus.tsx index 3fc4cf23..3f46197c 100644 --- a/signup-ui/src/pages/SignUpPage/PhoneStatus/PhoneStatus.tsx +++ b/signup-ui/src/pages/SignUpPage/PhoneStatus/PhoneStatus.tsx @@ -14,6 +14,7 @@ import { VerifyChallengeResponseDto } from "~typings/types"; import { SignUpForm } from "../SignUpPage"; import { setStepSelector, SignUpStep, useSignUpStore } from "../useSignUpStore"; +import { useSettings } from "../queries"; interface PhoneStatusProps { methods: UseFormReturn; @@ -21,6 +22,7 @@ interface PhoneStatusProps { export const PhoneStatus = ({ methods }: PhoneStatusProps) => { const { t } = useTranslation(); + const { data: settings } = useSettings(); const { setStep } = useSignUpStore( useCallback((state) => ({ setStep: setStepSelector(state) }), []) @@ -42,7 +44,7 @@ export const PhoneStatus = ({ methods }: PhoneStatusProps) => { const handleChallengeVerificationErrorRedirect = (e: any) => { e.preventDefault(); - window.location.href = getSignInRedirectURL(fromSignInHash); + window.location.href = getSignInRedirectURL(settings?.response.configs["signin.redirect-url"], fromSignInHash); }; const [challengeVerification] = useMutationState({ diff --git a/signup-ui/src/pages/SignUpPage/SignUpPopover.tsx b/signup-ui/src/pages/SignUpPage/SignUpPopover.tsx index bc95944d..22a42938 100644 --- a/signup-ui/src/pages/SignUpPage/SignUpPopover.tsx +++ b/signup-ui/src/pages/SignUpPage/SignUpPopover.tsx @@ -14,10 +14,12 @@ import { } from "~components/ui/alert-dialog"; import { getSignInRedirectURL } from "~utils/link"; +import { useSettings } from "./queries"; import { criticalErrorSelector, useSignUpStore } from "./useSignUpStore"; export const SignUpPopover = () => { const { t } = useTranslation(); + const { data: settings } = useSettings(); const { criticalError } = useSignUpStore( useCallback( @@ -31,7 +33,7 @@ export const SignUpPopover = () => { const handleAction = (e: any) => { e.preventDefault(); - window.location.href = getSignInRedirectURL(fromSignInHash); + window.location.href = getSignInRedirectURL(settings?.response.configs["signin.redirect-url"], fromSignInHash); }; return ( diff --git a/signup-ui/src/services/api.service.ts b/signup-ui/src/services/api.service.ts index cc687357..10151029 100644 --- a/signup-ui/src/services/api.service.ts +++ b/signup-ui/src/services/api.service.ts @@ -3,7 +3,10 @@ import { NavigateFunction } from "react-router-dom"; import { SOMETHING_WENT_WRONG } from "~constants/routes"; -export const API_BASE_URL = process.env.REACT_APP_API_BASE_URL ?? "/api/"; +const API_BASE_URL = + process.env.NODE_ENV === "development" + ? process.env.REACT_APP_API_BASE_URL + : window.origin + process.env.REACT_APP_API_BASE_URL; export class HttpError extends Error { code: number; diff --git a/signup-ui/src/typings/types.ts b/signup-ui/src/typings/types.ts index cdbf4ac8..3bec146b 100644 --- a/signup-ui/src/typings/types.ts +++ b/signup-ui/src/typings/types.ts @@ -72,6 +72,7 @@ interface SettingsConfig { "status.request.limit": number; "status.request.delay": number; "popup.timeout": number; + "signin.redirect-url": string; } export interface Settings { diff --git a/signup-ui/src/utils/link.ts b/signup-ui/src/utils/link.ts index 820aab3e..b0bcf301 100644 --- a/signup-ui/src/utils/link.ts +++ b/signup-ui/src/utils/link.ts @@ -1,10 +1,10 @@ import { Buffer } from "buffer"; -export const getSignInRedirectURL = (hash: string): string => { +export const getSignInRedirectURL = (redirectUrl: string | undefined, hash: string): string => { if (!!hash) { const signInQueryParams = Buffer.from(hash ?? "", "base64")?.toString(); - return process.env.REACT_APP_REDIRECT_SIGN_IN_URL + "?" + signInQueryParams; + return redirectUrl + "?" + signInQueryParams; } - return process.env.REACT_APP_REDIRECT_SIGN_UP_URL || "/"; + return "/"; };