From fc0f6d8e6bdc782a4cc814cf408ef6c750a30e13 Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Thu, 7 Sep 2023 20:55:18 +0530 Subject: [PATCH] add reseller hide phone number on sign up --- Accounts/package-lock.json | 27 +++++++++--- Accounts/package.json | 3 +- Accounts/src/Pages/Register.tsx | 75 ++++++++++++++++++++++++++++++--- Model/Models/Reseller.ts | 27 +++++++++++- 4 files changed, 118 insertions(+), 14 deletions(-) diff --git a/Accounts/package-lock.json b/Accounts/package-lock.json index dfd59b682c..ec0c584ee4 100644 --- a/Accounts/package-lock.json +++ b/Accounts/package-lock.json @@ -20,7 +20,8 @@ "react-router-dom": "^6.3.0", "react-scripts": "5.0.1", "the-new-css-reset": "^1.7.3", - "typescript": "^4.6.4" + "typescript": "^4.6.4", + "use-async-effect": "^2.2.7" }, "devDependencies": { "@testing-library/jest-dom": "^5.16.4", @@ -61,7 +62,7 @@ "moment-timezone": "^0.5.40", "nanoid": "^3.3.2", "nanoid-dictionary": "^4.3.0", - "posthog-js": "^1.37.0", + "posthog-js": "^1.77.0", "process": "^0.11.10", "reflect-metadata": "^0.1.13", "slugify": "^1.6.5", @@ -69,7 +70,7 @@ "uuid": "^8.3.2" }, "devDependencies": { - "@faker-js/faker": "^6.3.1", + "@faker-js/faker": "^8.0.2", "@types/jest": "^27.5.2", "@types/node": "^17.0.22", "jest": "^27.5.1", @@ -81,6 +82,7 @@ "version": "1.0.0", "license": "MIT", "dependencies": { + "@clickhouse/client": "^0.2.1", "@elastic/elasticsearch": "^8.1.0", "@opentelemetry/api": "^1.1.0", "@opentelemetry/auto-instrumentations-node": "^0.31.0", @@ -15015,6 +15017,14 @@ "requires-port": "^1.0.0" } }, + "node_modules/use-async-effect": { + "version": "2.2.7", + "resolved": "https://registry.npmjs.org/use-async-effect/-/use-async-effect-2.2.7.tgz", + "integrity": "sha512-Vq94tKPyo/9Nok4LOapV0GoGgZPhbeDW/bP6bulLPV4+lIoftaBRBBbGjTbM+j5W1Bm2EkUHJgapeu5YnQvKEA==", + "peerDependencies": { + "react": "^16.8.0 || ^17.0.0 || ^18.0.0" + } + }, "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", @@ -19843,7 +19853,7 @@ "Common": { "version": "file:../Common", "requires": { - "@faker-js/faker": "^6.3.1", + "@faker-js/faker": "^8.0.2", "@types/crypto-js": "^4.1.1", "@types/jest": "^27.5.2", "@types/nanoid-dictionary": "^4.2.0", @@ -19857,7 +19867,7 @@ "moment-timezone": "^0.5.40", "nanoid": "^3.3.2", "nanoid-dictionary": "^4.3.0", - "posthog-js": "^1.37.0", + "posthog-js": "^1.77.0", "process": "^0.11.10", "reflect-metadata": "^0.1.13", "slugify": "^1.6.5", @@ -19884,6 +19894,7 @@ "CommonServer": { "version": "file:../CommonServer", "requires": { + "@clickhouse/client": "^0.2.1", "@elastic/elasticsearch": "^8.1.0", "@faker-js/faker": "^6.3.1", "@opentelemetry/api": "^1.1.0", @@ -26759,6 +26770,12 @@ "requires-port": "^1.0.0" } }, + "use-async-effect": { + "version": "2.2.7", + "resolved": "https://registry.npmjs.org/use-async-effect/-/use-async-effect-2.2.7.tgz", + "integrity": "sha512-Vq94tKPyo/9Nok4LOapV0GoGgZPhbeDW/bP6bulLPV4+lIoftaBRBBbGjTbM+j5W1Bm2EkUHJgapeu5YnQvKEA==", + "requires": {} + }, "util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", diff --git a/Accounts/package.json b/Accounts/package.json index 2381b0c5b2..0177023467 100644 --- a/Accounts/package.json +++ b/Accounts/package.json @@ -15,7 +15,8 @@ "react-router-dom": "^6.3.0", "react-scripts": "5.0.1", "the-new-css-reset": "^1.7.3", - "typescript": "^4.6.4" + "typescript": "^4.6.4", + "use-async-effect": "^2.2.7" }, "scripts": { "dev": "npx nodemon", diff --git a/Accounts/src/Pages/Register.tsx b/Accounts/src/Pages/Register.tsx index f50f6cb3fb..0e911dcae3 100644 --- a/Accounts/src/Pages/Register.tsx +++ b/Accounts/src/Pages/Register.tsx @@ -1,4 +1,4 @@ -import React, { useEffect } from 'react'; +import React, { useEffect, useState } from 'react'; import ModelForm, { FormType } from 'CommonUI/src/Components/Forms/ModelForm'; import User from 'Model/Models/User'; import Link from 'CommonUI/src/Components/Link/Link'; @@ -16,17 +16,62 @@ import Fields from 'CommonUI/src/Components/Forms/Types/Fields'; import Dictionary from 'Common/Types/Dictionary'; import UiAnalytics from 'CommonUI/src/Utils/Analytics'; import LocalStorage from 'CommonUI/src/Utils/LocalStorage'; +import Reseller from 'Model/Models/Reseller'; +import ModelAPI, { ListResult } from 'CommonUI/src/Utils/ModelAPI/ModelAPI'; +import BaseAPI from 'CommonUI/src/Utils/API/API'; +import ErrorMessage from 'CommonUI/src/Components/ErrorMessage/ErrorMessage'; +import PageLoader from 'CommonUI/src/Components/Loader/PageLoader'; +import useAsyncEffect from 'use-async-effect'; const RegisterPage: () => JSX.Element = () => { const apiUrl: URL = SIGNUP_API_URL; const [initialValues, setInitialValues] = React.useState({}); + const [error, setError] = useState(''); + + const [isLoading, setIsLoading] = React.useState(false); + + + const [reseller, setResller] = React.useState(undefined); + if (UserUtil.isLoggedIn()) { Navigation.navigate(DASHBOARD_URL); } - useEffect(() => { + const fetchReseller = async (resellerId: string) => { + setIsLoading(true); + + try { + const reseller: ListResult = await ModelAPI.getList( + Reseller, + { + resellerId: resellerId + }, + 1, + 0, + { + hidePhoneNumberOnSignup: true, + }, + {}, + {} + ); + + if (reseller.data.length > 0) { + setResller(reseller.data[0]); + } + } catch (err) { + setError(BaseAPI.getFriendlyMessage(err)); + } + + setIsLoading(false); + + }; + + + + + useAsyncEffect(async () => { // if promo code is found, please save it in localstorage. if (Navigation.getQueryStringByName('promoCode')) { LocalStorage.setItem( @@ -35,11 +80,17 @@ const RegisterPage: () => JSX.Element = () => { ); } + if (Navigation.getQueryStringByName('email')) { setInitialValues({ email: Navigation.getQueryStringByName('email'), }); } + + // if promo code is found, please save it in localstorage. + if (Navigation.getQueryStringByName('partnerId')) { + await fetchReseller(Navigation.getQueryStringByName('partnerId')!) + } }, []); let formFields: Fields = [ @@ -74,8 +125,12 @@ const RegisterPage: () => JSX.Element = () => { placeholder: 'Acme, Inc.', required: true, title: 'Company Name', - }, - { + } + ]); + + // If reseller wants to hide phone number on sign up, we hide it. + if (!reseller || !reseller.hidePhoneNumberOnSignup) { + formFields.push({ field: { companyPhoneNumber: true, }, @@ -83,8 +138,8 @@ const RegisterPage: () => JSX.Element = () => { required: true, placeholder: '+11234567890', title: 'Phone Number', - }, - ]); + }); + } } formFields = formFields.concat([ @@ -117,6 +172,14 @@ const RegisterPage: () => JSX.Element = () => { }, ]); + if (error) { + return + } + + if (isLoading) { + return + } + return (
diff --git a/Model/Models/Reseller.ts b/Model/Models/Reseller.ts index 3368eedeca..07fc0ef882 100644 --- a/Model/Models/Reseller.ts +++ b/Model/Models/Reseller.ts @@ -17,7 +17,7 @@ import URL from 'Common/Types/API/URL'; @TableAccessControl({ create: [], - read: [Permission.ProjectOwner], + read: [Permission.ProjectOwner, Permission.Public], delete: [], update: [], }) @@ -36,7 +36,7 @@ import URL from 'Common/Types/API/URL'; export default class Reseller extends BaseModel { @ColumnAccessControl({ create: [], - read: [], + read: [Permission.Public], update: [], }) @TableColumn({ @@ -238,4 +238,27 @@ export default class Reseller extends BaseModel { transformer: URL.getDatabaseTransformer(), }) public changePlanLink?: URL = undefined; + + + @ColumnAccessControl({ + create: [], + read: [Permission.Public], + update: [], + }) + @TableColumn({ + required: false, + type: TableColumnType.ShortURL, + canReadOnRelationQuery: true, + title: 'Change Plan Link', + description: 'Reseller Change plan Link', + }) + @Column({ + nullable: true, + type: ColumnType.ShortURL, + length: ColumnLength.ShortURL, + transformer: URL.getDatabaseTransformer(), + }) + public hidePhoneNumberOnSignup?: boolean = undefined; + + }