@homefile/components-v2 2.49.6 → 2.49.7

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.
@@ -1,2 +1,2 @@
1
1
  import { HomiSmsI } from '../../../interfaces';
2
- export declare const HomiSms: ({ defaultEnabled, defaultSmsEnabled, sms, loading, onChange, onSave, }: HomiSmsI) => import("react/jsx-runtime").JSX.Element;
2
+ export declare const HomiSms: ({ mode, sms, loading, onChange, onSave, }: HomiSmsI) => import("react/jsx-runtime").JSX.Element;
@@ -1,40 +1,35 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { t } from 'i18next';
3
3
  import { Controller, useForm, useWatch } from 'react-hook-form';
4
- import { useEffect } from 'react';
4
+ import { useEffect, useState } from 'react';
5
5
  import * as yup from 'yup';
6
6
  import { Stack, Flex, Img, Text, Box, FormControl, FormLabel, Switch, Checkbox, Button, } from '@chakra-ui/react';
7
7
  import { SMS } from '../../../assets/images';
8
8
  import { ControlledInput, Loading } from '../../../components';
9
- export const HomiSms = ({ defaultEnabled = false, defaultSmsEnabled = true, sms = '', loading, onChange, onSave, }) => {
10
- var _a, _b, _c;
9
+ export const HomiSms = ({ mode = 'full', sms = '', loading, onChange, onSave, }) => {
10
+ var _a;
11
+ const isPhoneOnly = mode === 'phone-only';
11
12
  const { control, handleSubmit } = useForm({
12
- defaultValues: {
13
- enabled: defaultEnabled,
14
- smsEnabled: defaultSmsEnabled,
15
- sms,
16
- },
13
+ defaultValues: { sms },
17
14
  });
18
15
  const values = useWatch({ control });
19
- const isEnabled = (_a = values === null || values === void 0 ? void 0 : values.enabled) !== null && _a !== void 0 ? _a : false;
20
- const isSmsEnabled = (_b = values === null || values === void 0 ? void 0 : values.smsEnabled) !== null && _b !== void 0 ? _b : false;
21
- const smsValue = (_c = values === null || values === void 0 ? void 0 : values.sms) !== null && _c !== void 0 ? _c : '';
22
- const isEnabledChanged = isEnabled !== defaultEnabled;
23
- const isSmsEnabledChanged = isSmsEnabled !== defaultSmsEnabled;
24
- const isSmsChanged = smsValue !== sms;
25
- const showButtons = isEnabledChanged || isSmsEnabledChanged || isSmsChanged;
16
+ const smsValue = (_a = values === null || values === void 0 ? void 0 : values.sms) !== null && _a !== void 0 ? _a : '';
17
+ const [isEnabled, setIsEnabled] = useState(false);
18
+ const [isSmsEnabled, setIsSmsEnabled] = useState(true);
19
+ const showButtons = isPhoneOnly
20
+ ? smsValue !== sms
21
+ : smsValue !== sms || isEnabled || !isSmsEnabled;
26
22
  const handlePhoneValidation = (value) => {
23
+ if (isPhoneOnly)
24
+ return yup.string().required().min(10).max(10).isValidSync(value);
27
25
  if (isEnabled && isSmsEnabled)
28
26
  return yup.string().required().min(10).max(10).isValidSync(value);
29
27
  return true;
30
28
  };
31
29
  useEffect(() => {
32
30
  if (onChange && values) {
33
- onChange(values);
31
+ onChange({ sms: values.sms });
34
32
  }
35
33
  }, [onChange, values]);
36
- return (_jsxs(Box, { position: "relative", children: [loading && _jsx(Loading, {}), _jsxs(Stack, { bg: "lightBlue.2", px: "base", py: "4", spacing: "4", children: [_jsxs(Stack, { spacing: "3", children: [_jsxs(Flex, { align: "center", justify: "space-between", children: [_jsxs(Flex, { gap: "base", align: "center", children: [_jsx(Img, { src: SMS, alt: t('myProfile.details.homiSmsAlt') }), _jsx(Text, { fontSize: "sm", textTransform: "uppercase", children: t('myProfile.details.homiSmsTitle') })] }), _jsx(Controller, { name: "enabled", control: control, render: ({ field: { value, onChange, onBlur } }) => {
37
- const label = value ? 'ON' : 'OFF';
38
- return (_jsxs(FormControl, { display: "flex", alignItems: "center", w: "fit-content", children: [_jsx(FormLabel, { htmlFor: "homi-sms", mb: "0", fontSize: "sm", children: label }), _jsx(Switch, { id: "homi-sms", size: "lg", isChecked: value, onChange: onChange, onBlur: onBlur })] }));
39
- } })] }), _jsx(Text, { fontFamily: "secondary", lineHeight: "1.2", children: t('myProfile.details.homiSmsSubtitle') })] }), _jsxs(Flex, { gap: "base", align: "center", justify: "space-between", children: [_jsx(Controller, { name: "smsEnabled", control: control, render: ({ field: { value, onChange } }) => (_jsx(Checkbox, { size: "md", isChecked: value, onChange: (event) => onChange(event.target.checked), isDisabled: !isEnabled, children: _jsx(Text, { variant: "info", fontWeight: "normal", children: "SMS" }) })) }), _jsx(Box, { w: "75%", children: _jsx(Controller, { name: "sms", control: control, rules: { validate: handlePhoneValidation }, render: ({ field: { value, onBlur, onChange }, fieldState: { invalid }, }) => (_jsx(ControlledInput, { placeholder: t('myProfile.placeholders.sms'), onChange: onChange, onBlur: onBlur, value: value !== null && value !== void 0 ? value : '', type: "tel", hasError: invalid, errorMessage: `${t('forms.invalid')} ${t('forms.phone')}`, isDisabled: !isEnabled || !isSmsEnabled })) }) })] }), showButtons && onSave && (_jsx(Box, { w: "75%", alignSelf: "end", children: _jsx(Button, { variant: "secondaryFooter", type: "submit", bg: "neutral.white", fontWeight: "medium", onClick: handleSubmit(onSave), children: t('buttons.save').toUpperCase() }) }))] })] }));
34
+ return (_jsxs(Box, { position: "relative", children: [loading && _jsx(Loading, {}), _jsxs(Stack, { bg: "lightBlue.2", px: "base", py: "4", spacing: "4", children: [_jsxs(Stack, { spacing: "3", children: [_jsxs(Flex, { align: "center", justify: "space-between", children: [_jsxs(Flex, { gap: "base", align: "center", children: [_jsx(Img, { src: SMS, alt: t('myProfile.details.homiSmsAlt') }), _jsx(Text, { fontSize: "sm", textTransform: "uppercase", children: t('myProfile.details.homiSmsTitle') })] }), !isPhoneOnly && (_jsxs(FormControl, { display: "flex", alignItems: "center", w: "fit-content", children: [_jsx(FormLabel, { htmlFor: "homi-sms", mb: "0", fontSize: "sm", children: isEnabled ? 'ON' : 'OFF' }), _jsx(Switch, { id: "homi-sms", size: "lg", isChecked: isEnabled, onChange: (e) => setIsEnabled(e.target.checked) })] }))] }), _jsx(Text, { fontFamily: "secondary", lineHeight: "1.2", children: t('myProfile.details.homiSmsSubtitle') })] }), _jsxs(Flex, { gap: "base", align: "center", justify: "space-between", children: [!isPhoneOnly && (_jsx(Checkbox, { size: "md", isChecked: isSmsEnabled, onChange: (e) => setIsSmsEnabled(e.target.checked), isDisabled: !isEnabled, children: _jsx(Text, { variant: "info", fontWeight: "normal", children: "SMS" }) })), _jsx(Box, { w: isPhoneOnly ? '100%' : '75%', children: _jsx(Controller, { name: "sms", control: control, rules: { validate: handlePhoneValidation }, render: ({ field: { value, onBlur, onChange }, fieldState: { invalid }, }) => (_jsx(ControlledInput, { placeholder: t('myProfile.placeholders.sms'), onChange: onChange, onBlur: onBlur, value: value !== null && value !== void 0 ? value : '', type: "tel", hasError: invalid, errorMessage: `${t('forms.invalid')} ${t('forms.phone')}`, isDisabled: !isPhoneOnly && (!isEnabled || !isSmsEnabled) })) }) })] }), showButtons && onSave && (_jsx(Box, { w: "75%", alignSelf: "end", children: _jsx(Button, { variant: "secondaryFooter", type: "submit", bg: "neutral.white", fontWeight: "medium", onClick: handleSubmit(onSave), children: t('buttons.save').toUpperCase() }) }))] })] }));
40
35
  };
@@ -1,11 +1,8 @@
1
1
  export interface HomiSmsFormI {
2
- enabled: boolean;
3
- smsEnabled: boolean;
4
2
  sms?: string;
5
3
  }
6
4
  export interface HomiSmsI {
7
- defaultEnabled?: boolean;
8
- defaultSmsEnabled?: boolean;
5
+ mode?: 'full' | 'phone-only';
9
6
  sms?: string;
10
7
  loading?: boolean;
11
8
  onChange?: (value: HomiSmsFormI) => void;
@@ -14,5 +14,5 @@ export const MyProfilePanelComponent = () => {
14
14
  const handleCloseNewCreditCardPanel = () => setIsNewCreditCardPanelOpen(false);
15
15
  const handleOpenNewCreditCardPanel = () => setIsNewCreditCardPanelOpen(true);
16
16
  const handleError = () => setHasError(true);
17
- return (_jsxs(_Fragment, { children: [_jsx(RightPanel, { isOpen: true, onClose: action('onCloseClick'), children: _jsxs(MyProfilePanel, { children: [_jsx(MyProfileHeader, { onClose: action('onCloseClick') }), _jsx(MyProfileBody, { isLoading: false, account: _jsxs(_Fragment, { children: [_jsx(ActiveSubscription, { nextCharge: "2024-12-01", subscriptionPrice: 36, totalStorage: 2, totalUsed: 1, availableStorage: 200, state: 'trial' }), _jsx(Divider, { width: "calc(100% - 26px)", mx: "auto" }), _jsx(MonthlyCharge, { additionalPrice: 36, monthlyCharge: 36, monthDate: "03/01/2023", nextCharge: "01/12/2024", taxPercentage: 8.5, taxValue: 3.06, subtotal: 36.0 }), _jsx(CancelAccount, { label: "Contact Homefile", onClick: action('onCancelAccountClick') })] }), details: _jsxs(_Fragment, { children: [_jsx(UserDetails, { email: "gary.edmunds@gmail.com", firstName: "Gary", lastName: "Edmunds", onSave: action('onSaveClick'), bg: "#4CC35A" }), _jsx(TwoFactorSetting, { email: "gary.edmunds@gmail.com", sms: "2032409108", onChange: action('on2FAChangeClick'), onSave: action('onSaveClick'), defaultValue: "email", twoFactor: 'active' }), _jsx(HomiSms, { defaultEnabled: true, defaultSmsEnabled: true, sms: "2032409108", onChange: action('onHomiSmsChange'), onSave: action('onHomiSmsSave') })] }), payment: _jsxs(Box, { bg: "lightBlue.2", h: "inherit", children: [_jsx(CreditCardContainer, { cardNumber: "1234 5678 9012 3456", brand: "visa", onAddCard: action('onAddCard'), onDeleteCard: handleOpenNewCreditCardPanel, onSubmit: (data) => action('onDeleteCard')(data), cardHolder: "Gary Edmunds", cvv: "123", expirationMonth: "12", expirationYear: "2024" }), _jsx(PaymentReceipts, { receipts: receiptsMock, menuItems: menuMock })] }), rolePermissions: _jsx(RolePermissionsTab, { selected: featuresSelectedMock, onSelect: action('onSelect') }) })] }) }), _jsx(RightPanel, { isOpen: isNewCreditCardPanelOpen, onClose: handleCloseNewCreditCardPanel, children: _jsxs(MyProfilePanel, { children: [_jsx(MyProfileHeader, { onClose: handleCloseNewCreditCardPanel }), _jsxs(DrawerBody, { p: "0", children: [_jsx(NewCreditCardHeader, { onClick: handleCloseNewCreditCardPanel }), hasError && _jsx(CreditCardError, {}), _jsx(NewCreditCard, { hasError: hasError, onSubmit: handleError })] })] }) })] }));
17
+ return (_jsxs(_Fragment, { children: [_jsx(RightPanel, { isOpen: true, onClose: action('onCloseClick'), children: _jsxs(MyProfilePanel, { children: [_jsx(MyProfileHeader, { onClose: action('onCloseClick') }), _jsx(MyProfileBody, { isLoading: false, account: _jsxs(_Fragment, { children: [_jsx(ActiveSubscription, { nextCharge: "2024-12-01", subscriptionPrice: 36, totalStorage: 2, totalUsed: 1, availableStorage: 200, state: 'trial' }), _jsx(Divider, { width: "calc(100% - 26px)", mx: "auto" }), _jsx(MonthlyCharge, { additionalPrice: 36, monthlyCharge: 36, monthDate: "03/01/2023", nextCharge: "01/12/2024", taxPercentage: 8.5, taxValue: 3.06, subtotal: 36.0 }), _jsx(CancelAccount, { label: "Contact Homefile", onClick: action('onCancelAccountClick') })] }), details: _jsxs(_Fragment, { children: [_jsx(UserDetails, { email: "gary.edmunds@gmail.com", firstName: "Gary", lastName: "Edmunds", onSave: action('onSaveClick'), bg: "#4CC35A" }), _jsx(TwoFactorSetting, { email: "gary.edmunds@gmail.com", sms: "2032409108", onChange: action('on2FAChangeClick'), onSave: action('onSaveClick'), defaultValue: "email", twoFactor: 'active' }), _jsx(HomiSms, { sms: "2032409108", onChange: action('onHomiSmsChange'), onSave: action('onHomiSmsSave') })] }), payment: _jsxs(Box, { bg: "lightBlue.2", h: "inherit", children: [_jsx(CreditCardContainer, { cardNumber: "1234 5678 9012 3456", brand: "visa", onAddCard: action('onAddCard'), onDeleteCard: handleOpenNewCreditCardPanel, onSubmit: (data) => action('onDeleteCard')(data), cardHolder: "Gary Edmunds", cvv: "123", expirationMonth: "12", expirationYear: "2024" }), _jsx(PaymentReceipts, { receipts: receiptsMock, menuItems: menuMock })] }), rolePermissions: _jsx(RolePermissionsTab, { selected: featuresSelectedMock, onSelect: action('onSelect') }) })] }) }), _jsx(RightPanel, { isOpen: isNewCreditCardPanelOpen, onClose: handleCloseNewCreditCardPanel, children: _jsxs(MyProfilePanel, { children: [_jsx(MyProfileHeader, { onClose: handleCloseNewCreditCardPanel }), _jsxs(DrawerBody, { p: "0", children: [_jsx(NewCreditCardHeader, { onClick: handleCloseNewCreditCardPanel }), hasError && _jsx(CreditCardError, {}), _jsx(NewCreditCard, { hasError: hasError, onSubmit: handleError })] })] }) })] }));
18
18
  };
@@ -5,14 +5,12 @@ export default _default;
5
5
  export declare const HomiSmsEnabledComponent: {
6
6
  (args: HomiSmsI): import("react/jsx-runtime").JSX.Element;
7
7
  args: {
8
- defaultEnabled: boolean;
9
8
  sms: string;
10
9
  };
11
10
  };
12
11
  export declare const HomiSmsDisabledComponent: {
13
12
  (args: HomiSmsI): import("react/jsx-runtime").JSX.Element;
14
13
  args: {
15
- defaultEnabled: boolean;
16
14
  sms: string;
17
15
  };
18
16
  };
@@ -12,11 +12,9 @@ export default {
12
12
  };
13
13
  export const HomiSmsEnabledComponent = (args) => (_jsx(Box, { w: ['full', 'md'], p: "base", children: _jsx(HomiSms, Object.assign({}, args)) }));
14
14
  HomiSmsEnabledComponent.args = {
15
- defaultEnabled: true,
16
15
  sms: '512.806.5011',
17
16
  };
18
17
  export const HomiSmsDisabledComponent = (args) => (_jsx(HomiSmsEnabledComponent, Object.assign({}, args)));
19
18
  HomiSmsDisabledComponent.args = {
20
- defaultEnabled: false,
21
19
  sms: '512.806.5011',
22
20
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homefile/components-v2",
3
- "version": "2.49.6",
3
+ "version": "2.49.7",
4
4
  "author": "Homefile",
5
5
  "license": "UNLICENSED",
6
6
  "typings": "dist/index.d.ts",