From ceff8b291c99705bce6b5d23981190e5299e3403 Mon Sep 17 00:00:00 2001 From: polishq Date: Wed, 17 Jun 2020 16:39:44 -0400 Subject: [PATCH 1/2] Check account status on account create page --- CHANGELOG.md | 4 + docs/README.md | 1 + messages/context.json | 3 + messages/en.json | 3 + messages/pt.json | 3 + react/components/AccountCreate.tsx | 11 ++- react/components/AccountCreatePage.tsx | 2 +- .../AccountCreatePageController.tsx | 10 +- .../AccountCreatePages/IntroPage.tsx | 94 +++++++++++++++---- 9 files changed, 106 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 97de46b..6ab2c38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Changed + +- AccountCreatePage will check shopper's account status and forbid account signup if status is "approved", "rejected", or "under-review". + ## [0.0.11] - 2020-06-02 ### Fixed diff --git a/docs/README.md b/docs/README.md index c539bed..b4b7017 100644 --- a/docs/README.md +++ b/docs/README.md @@ -99,6 +99,7 @@ In order to apply CSS customizations in this and other blocks, follow the instru | `introPageRightIconTitle` | | `introPageRightIconText` | | `introPageButtonContainer` | +| `introPageAccountErrorContainer` | | `personalInfoPageContainer` | | `personalInfoInstructions` | | `personalInfoSection` | diff --git a/messages/context.json b/messages/context.json index ec669ba..1bddca3 100644 --- a/messages/context.json +++ b/messages/context.json @@ -7,6 +7,9 @@ "store/flowFinance.accountCreate.introPage.rightIconText": "store/flowFinance.accountCreate.introPage.rightIconText", "store/flowFinance.accountCreate.introPage.continue": "store/flowFinance.accountCreate.introPage.continue", "store/flowFinance.accountCreate.introPage.poweredBy": "store/flowFinance.accountCreate.introPage.poweredBy", + "store/flowFinance.accountCreate.introPage.accountErrors.underReview": "store/flowFinance.accountCreate.introPage.accountErrors.underReview", + "store/flowFinance.accountCreate.introPage.accountErrors.approved": "store/flowFinance.accountCreate.introPage.accountErrors.approved", + "store/flowFinance.accountCreate.introPage.accountErrors.rejected": "store/flowFinance.accountCreate.introPage.accountErrors.rejected", "store/flowFinance.accountCreate.cnpjLabel": "store/flowFinance.accountCreate.cnpjLabel", "store/flowFinance.accountCreate.cnpjError": "store/flowFinance.accountCreate.cnpjError", "store/flowFinance.accountCreate.preQualify.notQualifiedMessage": "store/flowFinance.accountCreate.preQualify.notQualifiedMessage", diff --git a/messages/en.json b/messages/en.json index 8d29a15..fa2ce0b 100644 --- a/messages/en.json +++ b/messages/en.json @@ -7,6 +7,9 @@ "store/flowFinance.accountCreate.introPage.rightIconText": "Uma vez liberado, seu crédito aparecerá como uma opção de pagamento no {storePaymentName}", "store/flowFinance.accountCreate.introPage.continue": "Peça seu crédito", "store/flowFinance.accountCreate.introPage.poweredBy": "Powered by", + "store/flowFinance.accountCreate.introPage.accountErrors.underReview": "Sua análise de crédito já está em andamento e em breve você vai receber uma mensagem com o resultado.", + "store/flowFinance.accountCreate.introPage.accountErrors.approved": "Seu crédito já está aprovado e está disponível na página do checkout como Financiamento Gympass Plus.", + "store/flowFinance.accountCreate.introPage.accountErrors.rejected": "Você tem um pedido de crédito rejeitado e não é possível pedir uma nova linha de crédito no momento.", "store/flowFinance.accountCreate.cnpjLabel": "CNPJ", "store/flowFinance.accountCreate.cnpjError": "Por favor insira um CNPJ válido.", "store/flowFinance.accountCreate.preQualify.notQualifiedMessage": "Infelizmente você não é elegível para pedir uma linha de crédito {storePaymentName}.{lineBreak}{lineBreak}Mas você ainda pode fazer compras no nosso site, basta selecionar outra forma de pagamento no checkout.", diff --git a/messages/pt.json b/messages/pt.json index f7ca3c3..e978a22 100644 --- a/messages/pt.json +++ b/messages/pt.json @@ -7,6 +7,9 @@ "store/flowFinance.accountCreate.introPage.rightIconText": "Uma vez liberado, seu crédito aparecerá como uma opção de pagamento no {storePaymentName}", "store/flowFinance.accountCreate.introPage.continue": "Peça seu crédito", "store/flowFinance.accountCreate.introPage.poweredBy": "Powered by", + "store/flowFinance.accountCreate.introPage.accountErrors.underReview": "Sua análise de crédito já está em andamento e em breve você vai receber uma mensagem com o resultado.", + "store/flowFinance.accountCreate.introPage.accountErrors.approved": "Seu crédito já está aprovado e está disponível na página do checkout como Financiamento Gympass Plus.", + "store/flowFinance.accountCreate.introPage.accountErrors.rejected": "Você tem um pedido de crédito rejeitado e não é possível pedir uma nova linha de crédito no momento.", "store/flowFinance.accountCreate.cnpjLabel": "CNPJ", "store/flowFinance.accountCreate.cnpjError": "Por favor insira um CNPJ válido.", "store/flowFinance.accountCreate.preQualify.notQualifiedMessage": "Infelizmente você não é elegível para pedir uma linha de crédito {storePaymentName}.{lineBreak}{lineBreak}Mas você ainda pode fazer compras no nosso site, basta selecionar outra forma de pagamento no checkout.", diff --git a/react/components/AccountCreate.tsx b/react/components/AccountCreate.tsx index eea194e..bfb71fb 100644 --- a/react/components/AccountCreate.tsx +++ b/react/components/AccountCreate.tsx @@ -8,14 +8,16 @@ import { import AccountCreatePageController from './AccountCreatePageController' import './AccountCreatePages/styles/global.css' -interface ExitProps { +interface Props { handleExit(): Promise + checkAccount?: boolean } const CSS_HANDLES = ['accountCreateContainer'] as const -const AccountCreate: StorefrontFunctionComponent = ({ +const AccountCreate: StorefrontFunctionComponent = ({ handleExit, + checkAccount = false, }) => { const handles = useCssHandles(CSS_HANDLES) return ( @@ -34,7 +36,10 @@ const AccountCreate: StorefrontFunctionComponent = ({ documentsComplete={initialAccountCreateState.documentsValid} >
- +
) diff --git a/react/components/AccountCreatePage.tsx b/react/components/AccountCreatePage.tsx index 77368da..ce002b6 100644 --- a/react/components/AccountCreatePage.tsx +++ b/react/components/AccountCreatePage.tsx @@ -25,7 +25,7 @@ const AccountCreatePage: StorefrontFunctionComponent = () => { style={{ maxWidth: 800, margin: '0 auto' }} > - + diff --git a/react/components/AccountCreatePageController.tsx b/react/components/AccountCreatePageController.tsx index 167f231..49ede55 100644 --- a/react/components/AccountCreatePageController.tsx +++ b/react/components/AccountCreatePageController.tsx @@ -13,8 +13,9 @@ import DocumentsPage from './AccountCreatePages/DocumentsPage' import SuccessPage from './AccountCreatePages/SuccessPage' import AppSettings from '../graphql/AppSettings.graphql' -interface ExitProps { +interface Props { handleExit: () => void + checkAccount: boolean } interface Settings { @@ -23,8 +24,9 @@ interface Settings { tosPdfPath: string } -const AccountCreatePageController: StorefrontFunctionComponent = ({ +const AccountCreatePageController: StorefrontFunctionComponent = ({ handleExit, + checkAccount, }) => { const { currentPage } = useAccountCreateState() const { data } = useQuery(AppSettings, { ssr: false }) @@ -35,7 +37,9 @@ const AccountCreatePageController: StorefrontFunctionComponent = ({ return ( - {currentPage === 1 && } + {currentPage === 1 && ( + + )} {currentPage === 2 && ( )} diff --git a/react/components/AccountCreatePages/IntroPage.tsx b/react/components/AccountCreatePages/IntroPage.tsx index 0c4709a..77636eb 100644 --- a/react/components/AccountCreatePages/IntroPage.tsx +++ b/react/components/AccountCreatePages/IntroPage.tsx @@ -1,5 +1,6 @@ -import React from 'react' +import React, { useEffect, useState } from 'react' import { FormattedMessage } from 'react-intl' +import { useQuery } from 'react-apollo' import { useCssHandles } from 'vtex.css-handles' import { Button, Divider } from 'vtex.styleguide' @@ -10,9 +11,11 @@ import { import IconMouse from '../../images/mouse.svg' import IconCart from '../../images/cart.svg' import FlowFinanceLogo from '../../images/flow-finance-logo.png' +import Profile from '../../graphql/Profile.graphql' -interface SettingsProps { +interface Props { settings: Settings + checkAccount: boolean } interface Settings { @@ -34,15 +37,50 @@ const CSS_HANDLES = [ 'introPageRightIconTitle', 'introPageRightIconText', `introPageButtonContainer`, + 'introPageAccountErrorContainer', `poweredByContainer`, ] as const -const IntroPage: StorefrontFunctionComponent = ({ +const IntroPage: StorefrontFunctionComponent = ({ settings, + checkAccount, }) => { const { currentPage } = useAccountCreateState() const dispatch = useAccountCreateDispatch() + const [accountStatus, setAccountStatus] = useState('none') const handles = useCssHandles(CSS_HANDLES) + const { data } = useQuery(Profile, { skip: !checkAccount }) + + async function postData(url = '', dataToPost = {}) { + const response = await fetch(url, { + method: 'POST', + mode: 'cors', + cache: 'no-cache', + credentials: 'same-origin', + headers: { + 'Content-Type': 'application/json', + }, + redirect: 'follow', + referrerPolicy: 'no-referrer', + body: JSON.stringify(dataToPost), + }) + if (!response.ok) { + console.error(response) + return response + } + return response.json() + } + + useEffect(() => { + if (data?.profile) { + postData(`/_v/api/connectors/flow-finance/get-loan-options`, { + email: data.profile.email, + total: 1000, + }).then(response => { + setAccountStatus('approved' || response.accountStatus) + }) + } + }, [data]) return (
@@ -96,25 +134,45 @@ const IntroPage: StorefrontFunctionComponent = ({
- +
+ +
+ {accountStatus === 'under-review' && ( + + )} + {accountStatus === 'approved' && ( + + )} + {accountStatus === 'rejected' && ( + + )} +
+
- Flow Finance + Flow Finance
From f7a85b6deca4d17882cf23bad300a2287858a702 Mon Sep 17 00:00:00 2001 From: polishq Date: Wed, 17 Jun 2020 16:43:53 -0400 Subject: [PATCH 2/2] Removed test account status value --- react/components/AccountCreatePages/IntroPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/react/components/AccountCreatePages/IntroPage.tsx b/react/components/AccountCreatePages/IntroPage.tsx index 77636eb..7502fbe 100644 --- a/react/components/AccountCreatePages/IntroPage.tsx +++ b/react/components/AccountCreatePages/IntroPage.tsx @@ -77,7 +77,7 @@ const IntroPage: StorefrontFunctionComponent = ({ email: data.profile.email, total: 1000, }).then(response => { - setAccountStatus('approved' || response.accountStatus) + setAccountStatus(response.accountStatus) }) } }, [data])