@homefile/components-v2 2.7.15 → 2.7.17
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.
- package/dist/components/myProfile/details/UserDetails.d.ts +1 -1
- package/dist/components/myProfile/details/UserDetails.js +19 -4
- package/dist/interfaces/myProfile/details/TwoFactorSetting.interface.d.ts +1 -0
- package/dist/stories/myProfile/details/UserDetails.stories.d.ts +1 -5
- package/dist/stories/myProfile/details/UserDetails.stories.js +8 -5
- package/package.json +1 -1
- package/src/components/myProfile/details/UserDetails.tsx +27 -12
- package/src/interfaces/myProfile/details/TwoFactorSetting.interface.ts +1 -0
- package/src/stories/myProfile/details/UserDetails.stories.tsx +8 -5
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { UserDetailsI } from '../../../interfaces';
|
|
2
|
-
export declare const UserDetails: ({ email, firstName, lastName, onSave, bg }: UserDetailsI) => import("react/jsx-runtime").JSX.Element;
|
|
2
|
+
export declare const UserDetails: ({ email, firstName, lastName, onSave, bg, }: UserDetailsI) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -17,9 +17,9 @@ const schema = yup.object({
|
|
|
17
17
|
.email(`${t('forms.invalid')} ${t('forms.email')}`)
|
|
18
18
|
.required(`${t('forms.email')} ${t('forms.required')}`),
|
|
19
19
|
});
|
|
20
|
-
export const UserDetails = ({ email, firstName, lastName, onSave, bg }) => {
|
|
20
|
+
export const UserDetails = ({ email, firstName, lastName, onSave, bg, }) => {
|
|
21
21
|
const nameInitials = `${firstName.charAt(0)}${lastName.charAt(0)}`.toUpperCase();
|
|
22
|
-
const { control, handleSubmit, reset, formState: { errors,
|
|
22
|
+
const { control, handleSubmit, reset, formState: { errors, isDirty }, } = useForm({
|
|
23
23
|
defaultValues: {
|
|
24
24
|
firstName,
|
|
25
25
|
lastName,
|
|
@@ -27,7 +27,13 @@ export const UserDetails = ({ email, firstName, lastName, onSave, bg }) => {
|
|
|
27
27
|
},
|
|
28
28
|
resolver: yupResolver(schema),
|
|
29
29
|
});
|
|
30
|
-
const
|
|
30
|
+
const handleOnSave = (data) => {
|
|
31
|
+
onSave(data);
|
|
32
|
+
reset(data, {
|
|
33
|
+
keepDirty: false,
|
|
34
|
+
keepTouched: false,
|
|
35
|
+
});
|
|
36
|
+
};
|
|
31
37
|
return (_jsxs(Flex, { align: "start", gap: "input.sm", bg: "lightBlue.2", p: "base", pb: "6", children: [_jsx(Center, { h: "121px", w: "121px", bg: bg, children: _jsx(Text, { fontSize: "5xl", fontWeight: "extrabold", fontFamily: "primary", color: "neutral.white", children: nameInitials }) }), _jsxs(Stack, { flex: "1", spacing: "input.sm", children: [_jsx(Controller, { name: "firstName", control: control, render: ({ field: { value, onBlur, onChange }, fieldState: { invalid }, }) => {
|
|
32
38
|
var _a;
|
|
33
39
|
return (_jsx(TextInput, { handleChange: onChange, placeholder: t('myProfile.placeholders.firstName'), value: value, onBlur: onBlur, hasError: invalid, errorMessage: (_a = errors.firstName) === null || _a === void 0 ? void 0 : _a.message }));
|
|
@@ -37,5 +43,14 @@ export const UserDetails = ({ email, firstName, lastName, onSave, bg }) => {
|
|
|
37
43
|
} }), _jsx(Controller, { name: "email", control: control, render: ({ field: { value, onBlur, onChange }, fieldState: { invalid }, }) => {
|
|
38
44
|
var _a;
|
|
39
45
|
return (_jsx(TextInput, { handleChange: onChange, placeholder: t('myProfile.placeholders.email'), value: value, onBlur: onBlur, hasError: invalid, errorMessage: (_a = errors.email) === null || _a === void 0 ? void 0 : _a.message }));
|
|
40
|
-
} }),
|
|
46
|
+
} }), isDirty && (_jsx(ContextButtons, { onCancel: () => {
|
|
47
|
+
reset({
|
|
48
|
+
firstName,
|
|
49
|
+
lastName,
|
|
50
|
+
email,
|
|
51
|
+
}, {
|
|
52
|
+
keepDirty: false,
|
|
53
|
+
keepTouched: false,
|
|
54
|
+
});
|
|
55
|
+
}, onSave: handleSubmit(handleOnSave) }))] })] }));
|
|
41
56
|
};
|
|
@@ -4,9 +4,5 @@ declare const _default: Meta<UserDetailsI>;
|
|
|
4
4
|
export default _default;
|
|
5
5
|
export declare const UserDetailsComponent: {
|
|
6
6
|
(args: UserDetailsI): import("react/jsx-runtime").JSX.Element;
|
|
7
|
-
args: {
|
|
8
|
-
email: string;
|
|
9
|
-
firstName: string;
|
|
10
|
-
lastName: string;
|
|
11
|
-
};
|
|
7
|
+
args: {};
|
|
12
8
|
};
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Box } from '@chakra-ui/react';
|
|
3
3
|
import { UserDetails } from '../../../components';
|
|
4
|
+
import { action } from '@storybook/addon-actions';
|
|
4
5
|
export default {
|
|
5
6
|
title: 'Components/MyProfile/Details',
|
|
6
7
|
component: UserDetails,
|
|
8
|
+
args: {
|
|
9
|
+
email: 'user@user.com',
|
|
10
|
+
firstName: 'Gary',
|
|
11
|
+
lastName: 'Edmunds',
|
|
12
|
+
onSave: action('onSave'),
|
|
13
|
+
},
|
|
7
14
|
};
|
|
8
15
|
export const UserDetailsComponent = (args) => {
|
|
9
16
|
return (_jsx(Box, { w: ['full', 'md'], p: "base", children: _jsx(UserDetails, Object.assign({}, args)) }));
|
|
10
17
|
};
|
|
11
|
-
UserDetailsComponent.args = {
|
|
12
|
-
email: 'user@user.com',
|
|
13
|
-
firstName: 'Gary',
|
|
14
|
-
lastName: 'Edmunds',
|
|
15
|
-
};
|
|
18
|
+
UserDetailsComponent.args = {};
|
package/package.json
CHANGED
|
@@ -26,7 +26,7 @@ export const UserDetails = ({
|
|
|
26
26
|
firstName,
|
|
27
27
|
lastName,
|
|
28
28
|
onSave,
|
|
29
|
-
bg
|
|
29
|
+
bg,
|
|
30
30
|
}: UserDetailsI) => {
|
|
31
31
|
const nameInitials = `${firstName.charAt(0)}${lastName.charAt(
|
|
32
32
|
0
|
|
@@ -36,7 +36,7 @@ export const UserDetails = ({
|
|
|
36
36
|
control,
|
|
37
37
|
handleSubmit,
|
|
38
38
|
reset,
|
|
39
|
-
formState: { errors,
|
|
39
|
+
formState: { errors, isDirty },
|
|
40
40
|
} = useForm<FormData>({
|
|
41
41
|
defaultValues: {
|
|
42
42
|
firstName,
|
|
@@ -46,16 +46,16 @@ export const UserDetails = ({
|
|
|
46
46
|
resolver: yupResolver(schema),
|
|
47
47
|
})
|
|
48
48
|
|
|
49
|
-
const
|
|
49
|
+
const handleOnSave = (data: FormData) => {
|
|
50
|
+
onSave(data)
|
|
51
|
+
reset(data, {
|
|
52
|
+
keepDirty: false,
|
|
53
|
+
keepTouched: false,
|
|
54
|
+
})
|
|
55
|
+
}
|
|
50
56
|
|
|
51
57
|
return (
|
|
52
|
-
<Flex
|
|
53
|
-
align="start"
|
|
54
|
-
gap="input.sm"
|
|
55
|
-
bg="lightBlue.2"
|
|
56
|
-
p="base"
|
|
57
|
-
pb="6"
|
|
58
|
-
>
|
|
58
|
+
<Flex align="start" gap="input.sm" bg="lightBlue.2" p="base" pb="6">
|
|
59
59
|
<Center h="121px" w="121px" bg={bg}>
|
|
60
60
|
<Text
|
|
61
61
|
fontSize="5xl"
|
|
@@ -118,8 +118,23 @@ export const UserDetails = ({
|
|
|
118
118
|
/>
|
|
119
119
|
)}
|
|
120
120
|
/>
|
|
121
|
-
{
|
|
122
|
-
<ContextButtons
|
|
121
|
+
{isDirty && (
|
|
122
|
+
<ContextButtons
|
|
123
|
+
onCancel={() => {
|
|
124
|
+
reset(
|
|
125
|
+
{
|
|
126
|
+
firstName,
|
|
127
|
+
lastName,
|
|
128
|
+
email,
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
keepDirty: false,
|
|
132
|
+
keepTouched: false,
|
|
133
|
+
}
|
|
134
|
+
)
|
|
135
|
+
}}
|
|
136
|
+
onSave={handleSubmit(handleOnSave)}
|
|
137
|
+
/>
|
|
123
138
|
)}
|
|
124
139
|
</Stack>
|
|
125
140
|
</Flex>
|
|
@@ -2,10 +2,17 @@ import { Meta } from '@storybook/react'
|
|
|
2
2
|
import { Box } from '@chakra-ui/react'
|
|
3
3
|
import { UserDetails } from '@/components'
|
|
4
4
|
import { UserDetailsI } from '@/interfaces'
|
|
5
|
+
import { action } from '@storybook/addon-actions'
|
|
5
6
|
|
|
6
7
|
export default {
|
|
7
8
|
title: 'Components/MyProfile/Details',
|
|
8
9
|
component: UserDetails,
|
|
10
|
+
args: {
|
|
11
|
+
email: 'user@user.com',
|
|
12
|
+
firstName: 'Gary',
|
|
13
|
+
lastName: 'Edmunds',
|
|
14
|
+
onSave: action('onSave'),
|
|
15
|
+
},
|
|
9
16
|
} as Meta<UserDetailsI>
|
|
10
17
|
|
|
11
18
|
export const UserDetailsComponent = (args: UserDetailsI) => {
|
|
@@ -16,8 +23,4 @@ export const UserDetailsComponent = (args: UserDetailsI) => {
|
|
|
16
23
|
)
|
|
17
24
|
}
|
|
18
25
|
|
|
19
|
-
UserDetailsComponent.args = {
|
|
20
|
-
email: 'user@user.com',
|
|
21
|
-
firstName: 'Gary',
|
|
22
|
-
lastName: 'Edmunds',
|
|
23
|
-
}
|
|
26
|
+
UserDetailsComponent.args = {}
|