Skip to content

Commit 25f4757

Browse files
Account v2 real account signup base (#12836)
* chore: real account signup base modal setup * chore: signup modal actions * chore: update package-lock --------- Co-authored-by: Likhith Kolayari <[email protected]>
1 parent 3429dd0 commit 25f4757

File tree

10 files changed

+289
-14
lines changed

10 files changed

+289
-14
lines changed

package-lock.json

+57
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/account-v2/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"react": "^17.0.2",
2424
"react-dom": "^17.0.2",
2525
"react-i18next": "^11.11.0",
26+
"react-modal": "^3.16.1",
2627
"react-router-dom": "^5.2.0",
2728
"react-transition-group": "4.4.2",
2829
"usehooks-ts": "^2.7.0",
@@ -33,6 +34,7 @@
3334
"@testing-library/user-event": "^13.5.0",
3435
"@types/css-modules": "^1.0.2",
3536
"@types/react-dom": "^18.0.0",
37+
"@types/react-modal": "^3.16.3",
3638
"@types/webpack": "^5.28.5",
3739
"@typescript-eslint/eslint-plugin": "5.45.0",
3840
"@typescript-eslint/parser": "5.45.0",

packages/account-v2/src/App.tsx

+24-14
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
11
import React from 'react';
22
import { APIProvider } from '@deriv/api';
3-
import { BrandDerivLogoCoralIcon } from '@deriv/quill-icons';
4-
import './index.scss';
53
import { BreakpointProvider } from '@deriv/quill-design';
64
import { FormProgress } from './components/form-progress';
5+
import SignupWizard from './components/SignupWizard';
6+
import { SignupWizardProvider, useSignupWizardContext } from './context/SignupWizardContext';
77
import { stepProgress } from './mocks/form-progress.mock';
8+
import './index.scss';
9+
10+
const TriggerSignupWizardModal: React.FC = () => {
11+
const { setIsWizardOpen } = useSignupWizardContext();
12+
13+
return <button onClick={() => setIsWizardOpen(true)}>Show SignupWizardModal</button>;
14+
};
815

9-
const App: React.FC = () => (
10-
<APIProvider standalone>
11-
<BreakpointProvider>
12-
<div className='text-heading-h1 text-solid-slate-500'>Account V2</div>
13-
<div className='p-300'>
14-
<BrandDerivLogoCoralIcon height='120px' width='120px' />
15-
</div>
16-
{/* [TODO]:Mock - Remove hardcoded initial value once isActive comes from Modal */}
17-
<FormProgress activeStep={1} steps={stepProgress} />
18-
</BreakpointProvider>
19-
</APIProvider>
20-
);
16+
const App: React.FC = () => {
17+
return (
18+
<APIProvider standalone>
19+
<BreakpointProvider>
20+
<div className=' text-solid-slate-500 text-heading-h1'>Account V2</div>
21+
<SignupWizardProvider>
22+
<SignupWizard />
23+
<TriggerSignupWizardModal />
24+
{/* [TODO]:Mock - Remove hardcoded initial value once isActive comes from Modal */}
25+
<FormProgress activeStep={1} steps={stepProgress} />
26+
</SignupWizardProvider>
27+
</BreakpointProvider>
28+
</APIProvider>
29+
);
30+
};
2131

2232
export default App;

packages/account-v2/src/components/.gitkeep

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import React from 'react';
2+
import { Button } from '@deriv/quill-design';
3+
import { useSignupWizardContext } from '../../../context/SignupWizardContext';
4+
5+
type TActions = {
6+
onSubmit: () => void;
7+
};
8+
9+
/**
10+
* @name Actions
11+
* @description The Actions component is used to navigate between steps in the SignupWizard component.
12+
* @param {Function} onSubmit - A function that is called when the Next button is clicked.
13+
* @example
14+
* const onSubmit = () => {
15+
* // do something
16+
* };
17+
* return (
18+
* <Actions onSubmit={onSubmit} />
19+
* );
20+
*/
21+
22+
const Actions: React.FC<TActions> = ({ onSubmit }) => {
23+
const {
24+
helpers: { canGoToPrevStep, goToPrevStep },
25+
} = useSignupWizardContext();
26+
27+
return (
28+
<div className='flex justify-end divide-y-75'>
29+
{canGoToPrevStep && (
30+
<Button
31+
className='btn btn--primary btn--medium mr-8 rounded-200 mr-400'
32+
colorStyle='black'
33+
onClick={goToPrevStep}
34+
size='md'
35+
variant='secondary'
36+
>
37+
Previous
38+
</Button>
39+
)}
40+
<Button className='btn btn--primary btn--medium mr-8 rounded-200' onClick={onSubmit} size='md'>
41+
Next
42+
</Button>
43+
</div>
44+
);
45+
};
46+
47+
export default Actions;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
type TCustomStyles = {
2+
content: ReactModal.Styles['content'];
3+
overlay: ReactModal.Styles['overlay'];
4+
};
5+
6+
export const CUSTOM_STYLES: TCustomStyles = {
7+
content: {
8+
background: 'none',
9+
border: 'none',
10+
borderRadius: 0,
11+
bottom: 'auto',
12+
left: '50%',
13+
margin: 0,
14+
marginRight: '-50%',
15+
padding: 0,
16+
right: 'auto',
17+
top: '50%',
18+
transform: 'translate(-50%, -50%)',
19+
transition: 'all 0.35s ease-in-out',
20+
},
21+
overlay: {
22+
backgroundColor: 'rgba(0, 0, 0, 0.72)',
23+
zIndex: 9999,
24+
},
25+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.ReactModal__Overlay {
2+
background-color: rgba(0, 0, 0, 0.72);
3+
z-index: 9999;
4+
}
5+
6+
.ReactModal__Content {
7+
opacity: 0;
8+
transition: all 350ms ease-in-out;
9+
10+
&--after-open {
11+
opacity: 1;
12+
bottom: auto;
13+
left: 50%;
14+
right: auto;
15+
top: 50%;
16+
transform: translate(-50%, -50%);
17+
border-radius: 0;
18+
border: none;
19+
padding: 0;
20+
margin: 0;
21+
background: none;
22+
}
23+
24+
&--before-close {
25+
opacity: 0;
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React, { useEffect } from 'react';
2+
import ReactModal from 'react-modal';
3+
import { StandaloneXmarkBoldIcon } from '@deriv/quill-icons';
4+
import { useSignupWizardContext } from '../../context/SignupWizardContext';
5+
import Actions from './Actions';
6+
import { CUSTOM_STYLES } from './helpers';
7+
import './index.scss';
8+
9+
const SignupWizard: React.FC = () => {
10+
const {
11+
currentStep,
12+
helpers: { goToNextStep },
13+
isWizardOpen,
14+
setIsWizardOpen,
15+
} = useSignupWizardContext();
16+
useEffect(() => {
17+
ReactModal.setAppElement('#v2_modal_root');
18+
}, []);
19+
return (
20+
<ReactModal
21+
isOpen={isWizardOpen}
22+
onRequestClose={() => setIsWizardOpen(false)}
23+
shouldCloseOnOverlayClick
24+
style={CUSTOM_STYLES}
25+
>
26+
<div className='bg-background-primary-base h-[71.7rem] w-[104rem] rounded-800 flex overflow-hidden'>
27+
<div className='min-w-[25.6rem] bg-[#f2f3f4] p-800'>Timeline</div>
28+
<div className='flex flex-col p-800 w-[100%] justify-between'>
29+
<StandaloneXmarkBoldIcon
30+
className='cursor-pointer absolute right-1200 top-1200'
31+
fill='#000000'
32+
onClick={() => setIsWizardOpen(false)}
33+
/>
34+
Current step: {currentStep}
35+
<Actions onSubmit={goToNextStep} />
36+
</div>
37+
</div>
38+
</ReactModal>
39+
);
40+
};
41+
42+
export default SignupWizard;

packages/account-v2/src/context/.gitkeep

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import React, { createContext, useContext, useMemo, useState } from 'react';
2+
import { useStep } from 'usehooks-ts';
3+
4+
type Helpers = ReturnType<typeof useStep>[1];
5+
6+
type TSignupWizardContext = {
7+
currentStep: number;
8+
helpers: Helpers;
9+
isWizardOpen: boolean;
10+
setIsWizardOpen: React.Dispatch<React.SetStateAction<boolean>>;
11+
};
12+
13+
type TSignupWizardProvider = {
14+
children: React.ReactNode;
15+
};
16+
17+
const initialHelpers: Helpers = {
18+
canGoToNextStep: false,
19+
canGoToPrevStep: false,
20+
goToNextStep: /* noop */ () => {
21+
/* noop */
22+
},
23+
goToPrevStep: /* noop */ () => {
24+
/* noop */
25+
},
26+
reset: /* noop */ () => {
27+
/* noop */
28+
},
29+
setStep: /* noop */ (() => {
30+
/* noop */
31+
}) as React.Dispatch<React.SetStateAction<number>>,
32+
};
33+
export const SignupWizardContext = createContext<TSignupWizardContext>({
34+
currentStep: 0,
35+
helpers: initialHelpers,
36+
isWizardOpen: false,
37+
setIsWizardOpen: /* noop */ () => {
38+
/* noop */
39+
},
40+
});
41+
42+
export const useSignupWizardContext = () => {
43+
const context = useContext<TSignupWizardContext>(SignupWizardContext);
44+
if (!context)
45+
throw new Error('useSignupWizardContext() must be called within a component wrapped in SignupWizardProvider.');
46+
47+
return context;
48+
};
49+
50+
export const SignupWizardProvider = ({ children }: TSignupWizardProvider) => {
51+
const [isWizardOpen, setIsWizardOpen] = useState(false);
52+
const [currentStep, helpers] = useStep(5);
53+
54+
const contextState = useMemo(
55+
() => ({
56+
currentStep,
57+
helpers,
58+
isWizardOpen,
59+
setIsWizardOpen,
60+
}),
61+
[currentStep, helpers, isWizardOpen]
62+
);
63+
64+
return <SignupWizardContext.Provider value={contextState}>{children}</SignupWizardContext.Provider>;
65+
};

0 commit comments

Comments
 (0)