@homefile/components-v2 2.7.18 → 2.7.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. package/dist/components/myProfile/details/TwoFactorDialog.d.ts +2 -0
  2. package/dist/components/myProfile/details/TwoFactorDialog.js +6 -0
  3. package/dist/components/myProfile/details/index.d.ts +1 -0
  4. package/dist/components/myProfile/details/index.js +1 -0
  5. package/dist/components/onboarding/pages/TwoFactor.d.ts +1 -1
  6. package/dist/components/onboarding/pages/TwoFactor.js +3 -3
  7. package/dist/interfaces/myProfile/details/TwoFactorDialog.interface.d.ts +8 -0
  8. package/dist/interfaces/myProfile/details/TwoFactorDialog.interface.js +1 -0
  9. package/dist/interfaces/myProfile/details/TwoFactorSetting.interface.d.ts +1 -1
  10. package/dist/interfaces/myProfile/details/index.d.ts +1 -0
  11. package/dist/interfaces/myProfile/details/index.js +1 -0
  12. package/dist/interfaces/pages/TwoFactor.interface.d.ts +3 -2
  13. package/dist/stories/myProfile/details/TwoFactorDialog.stories.d.ts +5 -0
  14. package/dist/stories/myProfile/details/TwoFactorDialog.stories.js +18 -0
  15. package/package.json +1 -1
  16. package/src/components/myProfile/details/TwoFactorDialog.tsx +27 -0
  17. package/src/components/myProfile/details/index.ts +1 -0
  18. package/src/components/onboarding/pages/TwoFactor.tsx +13 -10
  19. package/src/hooks/myProfile/useTwoFactorSetting.ts +4 -3
  20. package/src/interfaces/myProfile/details/TwoFactorDialog.interface.ts +8 -0
  21. package/src/interfaces/myProfile/details/TwoFactorSetting.interface.ts +1 -1
  22. package/src/interfaces/myProfile/details/index.ts +1 -0
  23. package/src/interfaces/pages/TwoFactor.interface.ts +3 -2
  24. package/src/stories/myProfile/details/TwoFactorDialog.stories.tsx +22 -0
@@ -0,0 +1,2 @@
1
+ import { TwoFactorDialogI } from '../../../interfaces';
2
+ export declare const TwoFactorDialog: ({ isOpen, isLoading, onClose, onResend, onReset, twoFactorMethod, }: TwoFactorDialogI) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,6 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Modal, ModalContent, ModalOverlay } from '@chakra-ui/react';
3
+ import { TwoFactor } from '../..';
4
+ export const TwoFactorDialog = ({ isOpen, isLoading = false, onClose, onResend, onReset, twoFactorMethod, }) => {
5
+ return (_jsxs(Modal, { isOpen: isOpen, onClose: onClose, children: [_jsx(ModalOverlay, {}), _jsx(ModalContent, { children: _jsx(TwoFactor, { twoFactorMethod: twoFactorMethod, isDialog: true, isLoading: isLoading, onResend: onResend, onReset: onReset }) })] }));
6
+ };
@@ -1,2 +1,3 @@
1
+ export * from './TwoFactorDialog';
1
2
  export * from './TwoFactorSetting';
2
3
  export * from './UserDetails';
@@ -1,2 +1,3 @@
1
+ export * from './TwoFactorDialog';
1
2
  export * from './TwoFactorSetting';
2
3
  export * from './UserDetails';
@@ -1,2 +1,2 @@
1
1
  import { TwoFactorI } from '../../../interfaces';
2
- export declare const TwoFactor: ({ handleReset, handleResend, isLoading, twoFactorMethod, }: TwoFactorI) => import("react/jsx-runtime").JSX.Element;
2
+ export declare const TwoFactor: ({ onReset, onResend, isDialog, isLoading, twoFactorMethod, }: TwoFactorI) => import("react/jsx-runtime").JSX.Element;
@@ -4,7 +4,7 @@ import { Box, Button, Text, Container, Stack, Center } from '@chakra-ui/react';
4
4
  import { Logo, Footer, ButtonLoader, TextInput, BasePageWrapper, } from '../..';
5
5
  import { isEmptyField } from '../../../utils';
6
6
  import { useTwoFactor } from '../../../hooks';
7
- export const TwoFactor = ({ handleReset, handleResend, isLoading, twoFactorMethod, }) => {
8
- const { code, handleInputChange, handleSubmit, isValidated } = useTwoFactor(handleReset);
9
- return (_jsxs(BasePageWrapper, { children: [_jsxs(Container, { size: "onboarding", boxShadow: "lg", children: [_jsx(Logo, {}), _jsxs(Stack, { my: "6", children: [_jsx(Text, { variant: "title", textAlign: "center", px: "10", children: t('reset.2FA.title') }), _jsxs(Text, { fontFamily: "secondary", textAlign: "center", px: ['10', '20'], children: [twoFactorMethod === 'email' && t('reset.2FA.subtitleEmail'), twoFactorMethod === 'sms' && t('reset.2FA.subtitleSms')] })] }), _jsx(Box, { px: ['container.sm', 'container.md', 'container.lg'], pb: "container.md", mb: "6", children: _jsxs(Stack, { spacing: "4", children: [_jsx(TextInput, { errorMessage: t('forms.code') + ' ' + t('forms.required'), hasError: isValidated && isEmptyField(code), id: "code", placeholder: t('reset.2FA.placeholder'), value: code, handleChange: handleInputChange }), _jsx(Button, { isLoading: isLoading, spinner: _jsx(ButtonLoader, {}), onClick: handleSubmit, children: t('forms.submit') }), _jsx(Center, { children: _jsx(Button, { onClick: handleResend, variant: "text", children: t('reset.2FA.resend') }) })] }) })] }), _jsx(Footer, {})] }));
7
+ export const TwoFactor = ({ onReset, onResend, isDialog, isLoading, twoFactorMethod, }) => {
8
+ const { code, handleInputChange, handleSubmit, isValidated } = useTwoFactor(onReset);
9
+ return (_jsxs(BasePageWrapper, { children: [_jsxs(Container, { size: "onboarding", boxShadow: !isDialog ? 'lg' : 'none', children: [_jsx(Logo, {}), _jsxs(Stack, { my: "6", children: [_jsx(Text, { variant: "title", textAlign: "center", px: "10", children: t('reset.2FA.title') }), _jsxs(Text, { fontFamily: "secondary", textAlign: "center", px: ['10', '20'], children: [twoFactorMethod === 'email' && t('reset.2FA.subtitleEmail'), twoFactorMethod === 'sms' && t('reset.2FA.subtitleSms')] })] }), _jsx(Box, { px: ['container.sm', 'container.md', 'container.lg'], pb: "container.md", mb: "6", children: _jsxs(Stack, { spacing: "4", children: [_jsx(TextInput, { errorMessage: t('forms.code') + ' ' + t('forms.required'), hasError: isValidated && isEmptyField(code), id: "code", placeholder: t('reset.2FA.placeholder'), value: code, handleChange: handleInputChange }), _jsx(Button, { isLoading: isLoading, spinner: _jsx(ButtonLoader, {}), onClick: handleSubmit, children: t('forms.submit') }), onResend && (_jsx(Center, { children: _jsx(Button, { onClick: onResend, variant: "text", children: t('reset.2FA.resend') }) }))] }) })] }), !isDialog && _jsx(Footer, {})] }));
10
10
  };
@@ -0,0 +1,8 @@
1
+ export interface TwoFactorDialogI {
2
+ isLoading?: boolean;
3
+ isOpen: boolean;
4
+ onClose: () => void;
5
+ onResend?: () => void;
6
+ onReset: (code: string) => void;
7
+ twoFactorMethod: 'sms' | 'email';
8
+ }
@@ -7,7 +7,7 @@ export interface TwoFactorSettingI {
7
7
  defaultValue?: string;
8
8
  email?: string;
9
9
  loading?: boolean;
10
- onChange?: (value: string) => void;
10
+ onChange?: (value: 'email' | 'sms') => void;
11
11
  onSave: (value: TwoFactorFormI) => void;
12
12
  sms?: string;
13
13
  twoFactor?: string;
@@ -1,2 +1,3 @@
1
+ export * from './TwoFactorDialog.interface';
1
2
  export * from './TwoFactorSetting.interface';
2
3
  export * from './UserDetails.interface';
@@ -1,2 +1,3 @@
1
+ export * from './TwoFactorDialog.interface';
1
2
  export * from './TwoFactorSetting.interface';
2
3
  export * from './UserDetails.interface';
@@ -1,6 +1,7 @@
1
1
  export interface TwoFactorI {
2
- handleResend: () => void;
3
- handleReset: (code: string) => void;
2
+ onResend?: () => void;
3
+ onReset: (code: string) => void;
4
+ isDialog?: boolean;
4
5
  isLoading: boolean;
5
6
  twoFactorMethod: 'sms' | 'email';
6
7
  }
@@ -0,0 +1,5 @@
1
+ import { Meta } from '@storybook/react';
2
+ import { TwoFactorDialogI } from '../../../interfaces';
3
+ declare const _default: Meta<TwoFactorDialogI>;
4
+ export default _default;
5
+ export declare const TwoFactorDialogComponent: (args: TwoFactorDialogI) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,18 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { TwoFactorDialog } from '../../../components';
3
+ import { action } from '@storybook/addon-actions';
4
+ export default {
5
+ title: 'Components/MyProfile/Details',
6
+ component: TwoFactorDialog,
7
+ args: {
8
+ onReset: action('onReset'),
9
+ onResend: action('onResend'),
10
+ onClose: action('onClose'),
11
+ twoFactorMethod: 'sms',
12
+ isLoading: false,
13
+ isOpen: true,
14
+ },
15
+ };
16
+ export const TwoFactorDialogComponent = (args) => {
17
+ return _jsx(TwoFactorDialog, Object.assign({}, args));
18
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homefile/components-v2",
3
- "version": "2.7.18",
3
+ "version": "2.7.20",
4
4
  "author": "Homefile",
5
5
  "license": "UNLICENSED",
6
6
  "typings": "dist/index.d.ts",
@@ -0,0 +1,27 @@
1
+ import { Modal, ModalContent, ModalOverlay } from '@chakra-ui/react'
2
+ import { TwoFactor } from '@/components'
3
+ import { TwoFactorDialogI } from '@/interfaces'
4
+
5
+ export const TwoFactorDialog = ({
6
+ isOpen,
7
+ isLoading = false,
8
+ onClose,
9
+ onResend,
10
+ onReset,
11
+ twoFactorMethod,
12
+ }: TwoFactorDialogI) => {
13
+ return (
14
+ <Modal isOpen={isOpen} onClose={onClose}>
15
+ <ModalOverlay />
16
+ <ModalContent>
17
+ <TwoFactor
18
+ twoFactorMethod={twoFactorMethod}
19
+ isDialog
20
+ isLoading={isLoading}
21
+ onResend={onResend}
22
+ onReset={onReset}
23
+ />
24
+ </ModalContent>
25
+ </Modal>
26
+ )
27
+ }
@@ -1,2 +1,3 @@
1
+ export * from './TwoFactorDialog'
1
2
  export * from './TwoFactorSetting'
2
3
  export * from './UserDetails'
@@ -12,17 +12,18 @@ import { TwoFactorI } from '@/interfaces'
12
12
  import { useTwoFactor } from '@/hooks'
13
13
 
14
14
  export const TwoFactor = ({
15
- handleReset,
16
- handleResend,
15
+ onReset,
16
+ onResend,
17
+ isDialog,
17
18
  isLoading,
18
19
  twoFactorMethod,
19
20
  }: TwoFactorI) => {
20
21
  const { code, handleInputChange, handleSubmit, isValidated } =
21
- useTwoFactor(handleReset)
22
+ useTwoFactor(onReset)
22
23
 
23
24
  return (
24
25
  <BasePageWrapper>
25
- <Container size="onboarding" boxShadow="lg">
26
+ <Container size="onboarding" boxShadow={!isDialog ? 'lg' : 'none'}>
26
27
  <Logo />
27
28
  <Stack my="6">
28
29
  <Text variant="title" textAlign="center" px="10">
@@ -55,15 +56,17 @@ export const TwoFactor = ({
55
56
  >
56
57
  {t('forms.submit')}
57
58
  </Button>
58
- <Center>
59
- <Button onClick={handleResend} variant="text">
60
- {t('reset.2FA.resend')}
61
- </Button>
62
- </Center>
59
+ {onResend && (
60
+ <Center>
61
+ <Button onClick={onResend} variant="text">
62
+ {t('reset.2FA.resend')}
63
+ </Button>
64
+ </Center>
65
+ )}
63
66
  </Stack>
64
67
  </Box>
65
68
  </Container>
66
- <Footer />
69
+ {!isDialog && <Footer />}
67
70
  </BasePageWrapper>
68
71
  )
69
72
  }
@@ -1,4 +1,4 @@
1
- import { useEffect, useState } from 'react'
1
+ import { useEffect } from 'react'
2
2
  import { useRadioGroup } from '@chakra-ui/react'
3
3
  import { useForm } from 'react-hook-form'
4
4
  import * as yup from 'yup'
@@ -15,7 +15,7 @@ export const useTwoFactorSetting = ({
15
15
  }: Partial<TwoFactorSettingI>) => {
16
16
  const altText = getIconAltText(Security)
17
17
 
18
- const handleRadioChange = (value: string) => {
18
+ const handleRadioChange = (value: 'email' | 'sms') => {
19
19
  onChange?.(value)
20
20
  }
21
21
 
@@ -56,7 +56,8 @@ export const useTwoFactorSetting = ({
56
56
  const isSmsChanged = smsValue !== sms
57
57
  const radioChanged = radioValue !== defaultValue && is2faEnabled
58
58
 
59
- const showButtons = isSwitchChanged || isEmailChanged || isSmsChanged || radioChanged
59
+ const showButtons =
60
+ isSwitchChanged || isEmailChanged || isSmsChanged || radioChanged
60
61
 
61
62
  const handlePhoneValidation = (value?: string): boolean => {
62
63
  if (radioValue === 'sms')
@@ -0,0 +1,8 @@
1
+ export interface TwoFactorDialogI {
2
+ isLoading?: boolean
3
+ isOpen: boolean
4
+ onClose: () => void
5
+ onResend?: () => void
6
+ onReset: (code: string) => void
7
+ twoFactorMethod: 'sms' | 'email'
8
+ }
@@ -8,7 +8,7 @@ export interface TwoFactorSettingI {
8
8
  defaultValue?: string
9
9
  email?: string
10
10
  loading?: boolean
11
- onChange?: (value: string) => void
11
+ onChange?: (value: 'email' | 'sms') => void
12
12
  onSave: (value: TwoFactorFormI) => void
13
13
  sms?: string
14
14
  twoFactor?: string
@@ -1,2 +1,3 @@
1
+ export * from './TwoFactorDialog.interface'
1
2
  export * from './TwoFactorSetting.interface'
2
3
  export * from './UserDetails.interface'
@@ -1,6 +1,7 @@
1
1
  export interface TwoFactorI {
2
- handleResend: () => void
3
- handleReset: (code: string) => void
2
+ onResend?: () => void
3
+ onReset: (code: string) => void
4
+ isDialog?: boolean
4
5
  isLoading: boolean
5
6
  twoFactorMethod: 'sms' | 'email'
6
7
  }
@@ -0,0 +1,22 @@
1
+ import { Meta } from '@storybook/react'
2
+ import { Box } from '@chakra-ui/react'
3
+ import { TwoFactorDialog } from '@/components'
4
+ import { action } from '@storybook/addon-actions'
5
+ import { TwoFactorDialogI } from '@/interfaces'
6
+
7
+ export default {
8
+ title: 'Components/MyProfile/Details',
9
+ component: TwoFactorDialog,
10
+ args: {
11
+ onReset: action('onReset'),
12
+ onResend: action('onResend'),
13
+ onClose: action('onClose'),
14
+ twoFactorMethod: 'sms',
15
+ isLoading: false,
16
+ isOpen: true,
17
+ },
18
+ } as Meta<TwoFactorDialogI>
19
+
20
+ export const TwoFactorDialogComponent = (args: TwoFactorDialogI) => {
21
+ return <TwoFactorDialog {...args} />
22
+ }