@sqrzro/admin 1.0.0-beta.1
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/.eslintrc +4 -0
- package/.gitattributes +1 -0
- package/.prettierrc +9 -0
- package/.storybook/main.js +40 -0
- package/.storybook/manager.js +4 -0
- package/.storybook/postcss.config.js +3 -0
- package/.storybook/preview.js +11 -0
- package/.storybook/theme.js +7 -0
- package/.stylelintrc +9 -0
- package/LICENSE +5 -0
- package/README.md +9 -0
- package/__mocks__/squarezero-utility.ts +40 -0
- package/assets/logo-horizontal-dark.svg +21 -0
- package/assets/logo-horizontal-white.svg +21 -0
- package/assets/logo-vertical-dark.svg +21 -0
- package/assets/logo-vertical-white.svg +21 -0
- package/dist/index.css +3554 -0
- package/dist/index.js +5099 -0
- package/dist/index.js.map +1 -0
- package/dist/types/components/Alert/index.d.ts +10 -0
- package/dist/types/components/Allow/index.d.ts +13 -0
- package/dist/types/components/App/index.d.ts +19 -0
- package/dist/types/components/AutoSuggest/index.d.ts +60 -0
- package/dist/types/components/Button/index.d.ts +36 -0
- package/dist/types/components/CalendarInput/index.d.ts +10 -0
- package/dist/types/components/CheckboxList/index.d.ts +4 -0
- package/dist/types/components/ConnectedDropdown/index.d.ts +8 -0
- package/dist/types/components/ConnectedList/index.d.ts +4 -0
- package/dist/types/components/ConnectedScene/index.d.ts +11 -0
- package/dist/types/components/ConnectedTable/index.d.ts +4 -0
- package/dist/types/components/ContentBlock/index.d.ts +6 -0
- package/dist/types/components/DateInput/index.d.ts +7 -0
- package/dist/types/components/Document/index.d.ts +6 -0
- package/dist/types/components/Dropdown/index.d.ts +14 -0
- package/dist/types/components/Fieldset/index.d.ts +11 -0
- package/dist/types/components/FileInput/index.d.ts +4 -0
- package/dist/types/components/FilterLink/index.d.ts +7 -0
- package/dist/types/components/Form/index.d.ts +11 -0
- package/dist/types/components/FormActions/index.d.ts +9 -0
- package/dist/types/components/FormField/index.d.ts +27 -0
- package/dist/types/components/FormRepeater/index.d.ts +8 -0
- package/dist/types/components/ImageInput/index.d.ts +4 -0
- package/dist/types/components/InfoPanel/index.d.ts +8 -0
- package/dist/types/components/Link/__mocks__/index.d.ts +6 -0
- package/dist/types/components/Link/index.d.ts +13 -0
- package/dist/types/components/List/index.d.ts +23 -0
- package/dist/types/components/ListActions/index.d.ts +9 -0
- package/dist/types/components/LoginForm/index.d.ts +3 -0
- package/dist/types/components/Message/index.d.ts +7 -0
- package/dist/types/components/ModalActions/index.d.ts +11 -0
- package/dist/types/components/MoneyInput/index.d.ts +10 -0
- package/dist/types/components/PasswordForm/index.d.ts +3 -0
- package/dist/types/components/PasswordInput/index.d.ts +8 -0
- package/dist/types/components/RadioList/index.d.ts +4 -0
- package/dist/types/components/Scene/index.d.ts +10 -0
- package/dist/types/components/SummaryList/index.d.ts +8 -0
- package/dist/types/components/Switch/index.d.ts +9 -0
- package/dist/types/components/Table/index.d.ts +13 -0
- package/dist/types/components/Tag/index.d.ts +8 -0
- package/dist/types/components/TextArea/index.d.ts +4 -0
- package/dist/types/components/TextInput/index.d.ts +17 -0
- package/dist/types/components/WebsiteInput/index.d.ts +10 -0
- package/dist/types/components/WeekCalendar/index.d.ts +12 -0
- package/dist/types/core/AppHeader/index.d.ts +3 -0
- package/dist/types/core/AppLogo/index.d.ts +6 -0
- package/dist/types/core/AppLogoImage/index.d.ts +3 -0
- package/dist/types/core/AppLogoPlaceholder/index.d.ts +3 -0
- package/dist/types/core/Assistive/index.d.ts +6 -0
- package/dist/types/core/Banner/index.d.ts +3 -0
- package/dist/types/core/BuildModal/index.d.ts +3 -0
- package/dist/types/core/Calendar/index.d.ts +11 -0
- package/dist/types/core/CalendarDay/index.d.ts +16 -0
- package/dist/types/core/CalendarMonth/index.d.ts +12 -0
- package/dist/types/core/CalendarNavigation/index.d.ts +9 -0
- package/dist/types/core/CalendarWeek/index.d.ts +14 -0
- package/dist/types/core/ChkRad/index.d.ts +10 -0
- package/dist/types/core/ChkRadIcon/index.d.ts +7 -0
- package/dist/types/core/ChkRadList/index.d.ts +15 -0
- package/dist/types/core/CloseButton/index.d.ts +9 -0
- package/dist/types/core/ConfirmModal/index.d.ts +3 -0
- package/dist/types/core/ConnectedRepeater/index.d.ts +26 -0
- package/dist/types/core/ConnectedRepeaterComponent/index.d.ts +24 -0
- package/dist/types/core/Container/index.d.ts +7 -0
- package/dist/types/core/DropdownPanel/index.d.ts +18 -0
- package/dist/types/core/EmptyMessage/index.d.ts +12 -0
- package/dist/types/core/ErrorBoundary/index.d.ts +15 -0
- package/dist/types/core/ErrorMessage/index.d.ts +8 -0
- package/dist/types/core/FilterItem/index.d.ts +10 -0
- package/dist/types/core/Filters/index.d.ts +11 -0
- package/dist/types/core/FixedActions/index.d.ts +12 -0
- package/dist/types/core/FormError/index.d.ts +6 -0
- package/dist/types/core/FormLabel/index.d.ts +8 -0
- package/dist/types/core/FormLegend/index.d.ts +6 -0
- package/dist/types/core/Header/index.d.ts +8 -0
- package/dist/types/core/Icon/index.d.ts +7 -0
- package/dist/types/core/IconButton/Icon/index.d.ts +7 -0
- package/dist/types/core/IconButton/index.d.ts +11 -0
- package/dist/types/core/InputPanel/index.d.ts +8 -0
- package/dist/types/core/ListItem/index.d.ts +16 -0
- package/dist/types/core/ListItemAction/index.d.ts +4 -0
- package/dist/types/core/ListItemActions/index.d.ts +8 -0
- package/dist/types/core/ListItemMetaItem/index.d.ts +10 -0
- package/dist/types/core/ListItemTitle/index.d.ts +9 -0
- package/dist/types/core/Loader/index.d.ts +6 -0
- package/dist/types/core/MeActions/index.d.ts +3 -0
- package/dist/types/core/MePanel/index.d.ts +9 -0
- package/dist/types/core/Modal/index.d.ts +12 -0
- package/dist/types/core/Navigation/index.d.ts +3 -0
- package/dist/types/core/NavigationDivider/index.d.ts +3 -0
- package/dist/types/core/NavigationItem/index.d.ts +7 -0
- package/dist/types/core/Pagination/index.d.ts +7 -0
- package/dist/types/core/PaginationItem/index.d.ts +7 -0
- package/dist/types/core/Panel/index.d.ts +8 -0
- package/dist/types/core/RadialProgress/index.d.ts +8 -0
- package/dist/types/core/StaticTextInput/index.d.ts +12 -0
- package/dist/types/core/Styled/index.d.ts +6 -0
- package/dist/types/core/SummaryListItem/index.d.ts +15 -0
- package/dist/types/core/TableActionsCell/index.d.ts +8 -0
- package/dist/types/core/TableCell/index.d.ts +8 -0
- package/dist/types/core/TableHead/index.d.ts +8 -0
- package/dist/types/core/TableRow/index.d.ts +13 -0
- package/dist/types/core/Tabs/index.d.ts +11 -0
- package/dist/types/core/TextInputAncillary/index.d.ts +11 -0
- package/dist/types/core/Toast/index.d.ts +3 -0
- package/dist/types/core/WeekCalendarDay/index.d.ts +14 -0
- package/dist/types/filters/BooleanFilter/index.d.ts +5 -0
- package/dist/types/filters/DateFilter/index.d.ts +5 -0
- package/dist/types/filters/DropdownFilter/index.d.ts +5 -0
- package/dist/types/filters/QuickDateFilter/index.d.ts +5 -0
- package/dist/types/filters/interfaces.d.ts +36 -0
- package/dist/types/hooks/useAccessiblePanel.d.ts +13 -0
- package/dist/types/hooks/useAppContext.d.ts +37 -0
- package/dist/types/hooks/useClickOutside.d.ts +3 -0
- package/dist/types/hooks/useConnectedList.d.ts +7 -0
- package/dist/types/hooks/useFilters.d.ts +3 -0
- package/dist/types/hooks/useForm.d.ts +26 -0
- package/dist/types/hooks/useFormData.d.ts +9 -0
- package/dist/types/hooks/useLayout.d.ts +6 -0
- package/dist/types/hooks/useModal.d.ts +12 -0
- package/dist/types/hooks/useVariant.d.ts +6 -0
- package/dist/types/index.d.ts +187 -0
- package/dist/types/scenes/Error404Scene.d.ts +3 -0
- package/dist/types/services/BuildService.d.ts +5 -0
- package/dist/types/services/ConfirmService.d.ts +12 -0
- package/dist/types/services/DateService.d.ts +17 -0
- package/dist/types/services/DownloadService.d.ts +5 -0
- package/dist/types/services/FilterComponentService.d.ts +8 -0
- package/dist/types/services/FilterService.d.ts +13 -0
- package/dist/types/services/FormatService.d.ts +7 -0
- package/dist/types/services/ToastService.d.ts +5 -0
- package/dist/types/utility/MockRouter/index.d.ts +2 -0
- package/dist/types/utility/StorybookPanel/index.d.ts +7 -0
- package/dist/types/utility/TestChangeHandler/index.d.ts +8 -0
- package/dist/types/utility/create-app.d.ts +4 -0
- package/dist/types/utility/interfaces.d.ts +72 -0
- package/dist/types/utility/prop-types.d.ts +40 -0
- package/docs/guides/01-installation.story.mdx +33 -0
- package/docs/guides/02-configuration.story.mdx +80 -0
- package/docs/guides/03-pages.story.mdx +18 -0
- package/docs/guides/04-integration.story.mdx +33 -0
- package/docs/guides/a11y.story.mdx +7 -0
- package/docs/guides/theming.story.mdx +7 -0
- package/docs/introduction.story.mdx +17 -0
- package/jest.config.js +19 -0
- package/package.json +101 -0
- package/postcss.config.js +3 -0
- package/rollup.config.js +36 -0
- package/scripts/create-exports.js +74 -0
- package/scripts/update-license.js +8 -0
- package/squarezero.config.js +5 -0
- package/src/components/Alert/Alert.module.css +50 -0
- package/src/components/Alert/Alert.spec.tsx +63 -0
- package/src/components/Alert/Alert.story.tsx +23 -0
- package/src/components/Alert/index.tsx +67 -0
- package/src/components/Allow/Allow.spec.tsx +37 -0
- package/src/components/Allow/index.tsx +42 -0
- package/src/components/App/App.module.css +22 -0
- package/src/components/App/App.spec.tsx +128 -0
- package/src/components/App/index.tsx +108 -0
- package/src/components/AutoSuggest/AutoSuggest.module.css +8 -0
- package/src/components/AutoSuggest/AutoSuggest.spec.tsx +211 -0
- package/src/components/AutoSuggest/AutoSuggest.story.tsx +30 -0
- package/src/components/AutoSuggest/index.tsx +216 -0
- package/src/components/Button/Button.module.css +95 -0
- package/src/components/Button/Button.spec.tsx +69 -0
- package/src/components/Button/Button.story.tsx +39 -0
- package/src/components/Button/index.tsx +99 -0
- package/src/components/CalendarInput/CalendarInput.module.css +8 -0
- package/src/components/CalendarInput/CalendarInput.spec.tsx +206 -0
- package/src/components/CalendarInput/CalendarInput.story.tsx +62 -0
- package/src/components/CalendarInput/index.tsx +122 -0
- package/src/components/CheckboxList/CheckboxList.spec.tsx +83 -0
- package/src/components/CheckboxList/index.tsx +53 -0
- package/src/components/ConnectedDropdown/index.tsx +56 -0
- package/src/components/ConnectedList/index.tsx +15 -0
- package/src/components/ConnectedScene/index.tsx +95 -0
- package/src/components/ConnectedTable/index.tsx +17 -0
- package/src/components/ContentBlock/ContentBlock.module.css +8 -0
- package/src/components/ContentBlock/ContentBlock.spec.tsx +15 -0
- package/src/components/ContentBlock/index.tsx +16 -0
- package/src/components/DateInput/DateInput.module.css +15 -0
- package/src/components/DateInput/DateInput.spec.tsx +91 -0
- package/src/components/DateInput/index.tsx +149 -0
- package/src/components/Document/index.tsx +20 -0
- package/src/components/Dropdown/Dropdown.module.css +8 -0
- package/src/components/Dropdown/Dropdown.spec.tsx +286 -0
- package/src/components/Dropdown/Dropdown.story.tsx +53 -0
- package/src/components/Dropdown/index.tsx +224 -0
- package/src/components/Fieldset/Fieldset.spec.tsx +22 -0
- package/src/components/Fieldset/Fieldset.story.tsx +21 -0
- package/src/components/Fieldset/index.tsx +30 -0
- package/src/components/FileInput/FileInput.module.css +18 -0
- package/src/components/FileInput/FileInput.spec.tsx +42 -0
- package/src/components/FileInput/FileInput.story.tsx +6 -0
- package/src/components/FileInput/index.tsx +72 -0
- package/src/components/FilterLink/FilterLink.module.css +9 -0
- package/src/components/FilterLink/FilterLink.spec.tsx +20 -0
- package/src/components/FilterLink/index.tsx +31 -0
- package/src/components/Form/Form.spec.tsx +68 -0
- package/src/components/Form/index.tsx +87 -0
- package/src/components/FormActions/FormActions.spec.tsx +10 -0
- package/src/components/FormActions/FormActions.story.tsx +23 -0
- package/src/components/FormActions/index.tsx +31 -0
- package/src/components/FormField/FormField.module.css +71 -0
- package/src/components/FormField/FormField.spec.tsx +137 -0
- package/src/components/FormField/FormField.story.tsx +22 -0
- package/src/components/FormField/index.tsx +162 -0
- package/src/components/FormRepeater/FormRepeater.module.css +3 -0
- package/src/components/FormRepeater/FormRepeater.spec.tsx +127 -0
- package/src/components/FormRepeater/index.tsx +118 -0
- package/src/components/ImageInput/ImageInput.module.css +74 -0
- package/src/components/ImageInput/ImageInput.spec.tsx +45 -0
- package/src/components/ImageInput/ImageInput.story.tsx +6 -0
- package/src/components/ImageInput/index.tsx +91 -0
- package/src/components/InfoPanel/InfoPanel.module.css +18 -0
- package/src/components/InfoPanel/InfoPanel.spec.tsx +15 -0
- package/src/components/InfoPanel/InfoPanel.story.tsx +32 -0
- package/src/components/InfoPanel/index.tsx +25 -0
- package/src/components/Link/Link.spec.tsx +62 -0
- package/src/components/Link/__mocks__/index.tsx +24 -0
- package/src/components/Link/index.tsx +51 -0
- package/src/components/List/List.module.css +9 -0
- package/src/components/List/List.spec.tsx +311 -0
- package/src/components/List/List.story.tsx +92 -0
- package/src/components/List/index.tsx +79 -0
- package/src/components/ListActions/ListActions.spec.tsx +10 -0
- package/src/components/ListActions/ListActions.story.tsx +6 -0
- package/src/components/ListActions/index.tsx +31 -0
- package/src/components/LoginForm/LoginForm.module.css +21 -0
- package/src/components/LoginForm/LoginForm.spec.tsx +63 -0
- package/src/components/LoginForm/index.tsx +102 -0
- package/src/components/Message/Message.module.css +14 -0
- package/src/components/Message/Message.spec.tsx +20 -0
- package/src/components/Message/index.tsx +27 -0
- package/src/components/ModalActions/ModalActions.module.css +5 -0
- package/src/components/ModalActions/ModalActions.spec.tsx +53 -0
- package/src/components/ModalActions/ModalActions.story.tsx +6 -0
- package/src/components/ModalActions/index.tsx +47 -0
- package/src/components/MoneyInput/MoneyInput.spec.tsx +17 -0
- package/src/components/MoneyInput/MoneyInput.story.tsx +6 -0
- package/src/components/MoneyInput/index.tsx +16 -0
- package/src/components/PasswordForm/PasswordForm.module.css +21 -0
- package/src/components/PasswordForm/index.tsx +94 -0
- package/src/components/PasswordInput/PasswordInput.module.css +23 -0
- package/src/components/PasswordInput/PasswordInput.spec.tsx +31 -0
- package/src/components/PasswordInput/PasswordInput.story.tsx +16 -0
- package/src/components/PasswordInput/index.tsx +27 -0
- package/src/components/RadioList/RadioList.spec.tsx +45 -0
- package/src/components/RadioList/index.tsx +10 -0
- package/src/components/Scene/Scene.spec.tsx +123 -0
- package/src/components/Scene/Scene.story.tsx +6 -0
- package/src/components/Scene/index.tsx +58 -0
- package/src/components/SummaryList/SummaryList.module.css +16 -0
- package/src/components/SummaryList/SummaryList.spec.tsx +77 -0
- package/src/components/SummaryList/SummaryList.story.tsx +11 -0
- package/src/components/SummaryList/index.tsx +37 -0
- package/src/components/Switch/Switch.module.css +86 -0
- package/src/components/Switch/Switch.spec.tsx +64 -0
- package/src/components/Switch/index.tsx +85 -0
- package/src/components/Table/Table.module.css +14 -0
- package/src/components/Table/Table.spec.tsx +128 -0
- package/src/components/Table/Table.story.tsx +101 -0
- package/src/components/Table/index.tsx +114 -0
- package/src/components/Tag/Tag.module.css +37 -0
- package/src/components/Tag/Tag.spec.tsx +10 -0
- package/src/components/Tag/Tag.story.tsx +55 -0
- package/src/components/Tag/index.tsx +27 -0
- package/src/components/TextArea/TextArea.module.css +23 -0
- package/src/components/TextArea/TextArea.spec.tsx +77 -0
- package/src/components/TextArea/index.tsx +59 -0
- package/src/components/TextInput/TextInput.module.css +57 -0
- package/src/components/TextInput/TextInput.spec.tsx +134 -0
- package/src/components/TextInput/TextInput.story.tsx +24 -0
- package/src/components/TextInput/index.tsx +146 -0
- package/src/components/WebsiteInput/WebsiteInput.spec.tsx +17 -0
- package/src/components/WebsiteInput/index.tsx +16 -0
- package/src/components/WeekCalendar/WeekCalendar.module.css +19 -0
- package/src/components/WeekCalendar/index.tsx +80 -0
- package/src/core/AppHeader/index.tsx +23 -0
- package/src/core/AppLogo/AppLogo.module.css +19 -0
- package/src/core/AppLogo/index.tsx +33 -0
- package/src/core/AppLogoImage/index.tsx +19 -0
- package/src/core/AppLogoPlaceholder/index.tsx +26 -0
- package/src/core/Assistive/Assistive.module.css +10 -0
- package/src/core/Assistive/index.tsx +18 -0
- package/src/core/Banner/Banner.module.css +36 -0
- package/src/core/Banner/index.tsx +25 -0
- package/src/core/BuildModal/index.tsx +119 -0
- package/src/core/Calendar/index.tsx +116 -0
- package/src/core/CalendarDay/CalendarDay.module.css +61 -0
- package/src/core/CalendarDay/index.tsx +82 -0
- package/src/core/CalendarMonth/CalendarMonth.module.css +13 -0
- package/src/core/CalendarMonth/index.tsx +101 -0
- package/src/core/CalendarNavigation/CalendarNavigation.module.css +26 -0
- package/src/core/CalendarNavigation/index.tsx +56 -0
- package/src/core/CalendarWeek/index.tsx +95 -0
- package/src/core/ChkRad/ChkRad.module.css +31 -0
- package/src/core/ChkRad/ChkRad.spec.tsx +72 -0
- package/src/core/ChkRad/index.tsx +80 -0
- package/src/core/ChkRadIcon/ChkRadIcon.module.css +28 -0
- package/src/core/ChkRadIcon/index.tsx +33 -0
- package/src/core/ChkRadList/ChkRadList.module.css +10 -0
- package/src/core/ChkRadList/index.tsx +85 -0
- package/src/core/CloseButton/CloseButton.spec.tsx +36 -0
- package/src/core/CloseButton/index.tsx +31 -0
- package/src/core/ConfirmModal/ConfirmModal.spec.tsx +88 -0
- package/src/core/ConfirmModal/index.tsx +51 -0
- package/src/core/ConnectedRepeater/index.tsx +248 -0
- package/src/core/ConnectedRepeaterComponent/index.tsx +66 -0
- package/src/core/Container/Container.module.css +12 -0
- package/src/core/Container/index.tsx +35 -0
- package/src/core/DropdownPanel/DropdownPanel.module.css +68 -0
- package/src/core/DropdownPanel/index.tsx +92 -0
- package/src/core/EmptyMessage/EmptyMessage.module.css +18 -0
- package/src/core/EmptyMessage/index.tsx +31 -0
- package/src/core/ErrorBoundary/ErrorBoundary.spec.tsx +33 -0
- package/src/core/ErrorBoundary/index.tsx +42 -0
- package/src/core/ErrorMessage/ErrorMessage.module.css +25 -0
- package/src/core/ErrorMessage/ErrorMessage.spec.tsx +31 -0
- package/src/core/ErrorMessage/index.tsx +37 -0
- package/src/core/FilterItem/FilterItem.module.css +104 -0
- package/src/core/FilterItem/index.tsx +164 -0
- package/src/core/Filters/Filters.module.css +86 -0
- package/src/core/Filters/Filters.spec.tsx +533 -0
- package/src/core/Filters/index.tsx +158 -0
- package/src/core/FixedActions/FixedActions.module.css +24 -0
- package/src/core/FixedActions/index.tsx +52 -0
- package/src/core/FormError/FormError.module.css +7 -0
- package/src/core/FormError/index.tsx +18 -0
- package/src/core/FormLabel/FormLabel.module.css +15 -0
- package/src/core/FormLabel/index.tsx +25 -0
- package/src/core/FormLegend/FormLegend.module.css +13 -0
- package/src/core/FormLegend/index.tsx +18 -0
- package/src/core/Header/Header.module.css +35 -0
- package/src/core/Header/index.tsx +37 -0
- package/src/core/Icon/Icon.spec.tsx +31 -0
- package/src/core/Icon/index.tsx +64 -0
- package/src/core/IconButton/Icon/Icon.spec.tsx +31 -0
- package/src/core/IconButton/Icon/index.tsx +64 -0
- package/src/core/IconButton/IconButton.module.css +32 -0
- package/src/core/IconButton/index.tsx +55 -0
- package/src/core/InputPanel/InputPanel.module.css +70 -0
- package/src/core/InputPanel/index.tsx +28 -0
- package/src/core/ListItem/ListItem.module.css +28 -0
- package/src/core/ListItem/ListItem.story.tsx +28 -0
- package/src/core/ListItem/index.tsx +99 -0
- package/src/core/ListItemAction/ListItemAction.module.css +28 -0
- package/src/core/ListItemAction/index.tsx +30 -0
- package/src/core/ListItemActions/ListItemActions.module.css +94 -0
- package/src/core/ListItemActions/index.tsx +55 -0
- package/src/core/ListItemMetaItem/ListItemMetaItem.module.css +18 -0
- package/src/core/ListItemMetaItem/index.tsx +54 -0
- package/src/core/ListItemTitle/ListItemTitle.module.css +14 -0
- package/src/core/ListItemTitle/ListItemTitle.spec.tsx +33 -0
- package/src/core/ListItemTitle/index.tsx +72 -0
- package/src/core/Loader/Loader.module.css +57 -0
- package/src/core/Loader/Loader.story.tsx +8 -0
- package/src/core/Loader/index.tsx +27 -0
- package/src/core/MeActions/MeActions.module.css +45 -0
- package/src/core/MeActions/index.tsx +46 -0
- package/src/core/MePanel/MePanel.module.css +75 -0
- package/src/core/MePanel/index.tsx +45 -0
- package/src/core/Modal/Modal.module.css +84 -0
- package/src/core/Modal/Modal.spec.tsx +51 -0
- package/src/core/Modal/index.tsx +66 -0
- package/src/core/Navigation/Navigation.module.css +83 -0
- package/src/core/Navigation/Navigation.spec.tsx +101 -0
- package/src/core/Navigation/index.tsx +109 -0
- package/src/core/NavigationDivider/NavigationDivider.module.css +18 -0
- package/src/core/NavigationDivider/index.tsx +13 -0
- package/src/core/NavigationItem/NavigationItem.module.css +51 -0
- package/src/core/NavigationItem/index.tsx +59 -0
- package/src/core/Pagination/Pagination.module.css +15 -0
- package/src/core/Pagination/index.tsx +100 -0
- package/src/core/PaginationItem/PaginationItem.module.css +33 -0
- package/src/core/PaginationItem/index.tsx +46 -0
- package/src/core/Panel/Panel.module.css +15 -0
- package/src/core/Panel/index.tsx +31 -0
- package/src/core/RadialProgress/RadialProgress.module.css +78 -0
- package/src/core/RadialProgress/index.tsx +52 -0
- package/src/core/StaticTextInput/StaticTextInput.module.css +79 -0
- package/src/core/StaticTextInput/StaticTextInput.spec.tsx +133 -0
- package/src/core/StaticTextInput/index.tsx +114 -0
- package/src/core/Styled/Styled.spec.tsx +38 -0
- package/src/core/Styled/Styled.story.tsx +10 -0
- package/src/core/Styled/index.tsx +62 -0
- package/src/core/SummaryListItem/SummaryListItem.module.css +28 -0
- package/src/core/SummaryListItem/index.tsx +60 -0
- package/src/core/TableActionsCell/TableActionsCell.module.css +3 -0
- package/src/core/TableActionsCell/index.tsx +37 -0
- package/src/core/TableCell/TableCell.module.css +16 -0
- package/src/core/TableCell/index.tsx +39 -0
- package/src/core/TableHead/TableHead.module.css +12 -0
- package/src/core/TableHead/index.tsx +48 -0
- package/src/core/TableRow/index.tsx +64 -0
- package/src/core/Tabs/Tabs.module.css +50 -0
- package/src/core/Tabs/index.tsx +94 -0
- package/src/core/TextInputAncillary/TextInputAncillary.module.css +64 -0
- package/src/core/TextInputAncillary/index.tsx +72 -0
- package/src/core/Toast/Toast.module.css +55 -0
- package/src/core/Toast/Toast.spec.tsx +78 -0
- package/src/core/Toast/index.tsx +81 -0
- package/src/core/WeekCalendarDay/WeekCalendarDay.module.css +32 -0
- package/src/core/WeekCalendarDay/index.tsx +68 -0
- package/src/filters/BooleanFilter/index.tsx +46 -0
- package/src/filters/DateFilter/index.tsx +36 -0
- package/src/filters/DropdownFilter/index.tsx +53 -0
- package/src/filters/QuickDateFilter/index.tsx +74 -0
- package/src/filters/interfaces.ts +40 -0
- package/src/hooks/useAccessiblePanel.spec.tsx +88 -0
- package/src/hooks/useAccessiblePanel.ts +74 -0
- package/src/hooks/useAppContext.ts +77 -0
- package/src/hooks/useClickOutside.ts +49 -0
- package/src/hooks/useConnectedList.ts +26 -0
- package/src/hooks/useFilters.ts +26 -0
- package/src/hooks/useForm.spec.ts +126 -0
- package/src/hooks/useForm.ts +99 -0
- package/src/hooks/useFormData.spec.ts +40 -0
- package/src/hooks/useFormData.ts +27 -0
- package/src/hooks/useLayout.spec.ts +55 -0
- package/src/hooks/useLayout.ts +29 -0
- package/src/hooks/useModal.spec.tsx +63 -0
- package/src/hooks/useModal.ts +60 -0
- package/src/hooks/useVariant.spec.ts +14 -0
- package/src/hooks/useVariant.ts +34 -0
- package/src/index.ts +194 -0
- package/src/scenes/Error404Scene.tsx +5 -0
- package/src/services/BuildService.spec.ts +56 -0
- package/src/services/BuildService.ts +34 -0
- package/src/services/ConfirmService.ts +21 -0
- package/src/services/DateService.spec.ts +87 -0
- package/src/services/DateService.ts +137 -0
- package/src/services/DownloadService.spec.ts +29 -0
- package/src/services/DownloadService.ts +14 -0
- package/src/services/FilterComponentService.tsx +46 -0
- package/src/services/FilterService.spec.ts +87 -0
- package/src/services/FilterService.ts +58 -0
- package/src/services/FormatService.spec.ts +83 -0
- package/src/services/FormatService.ts +55 -0
- package/src/services/ToastService.spec.ts +44 -0
- package/src/services/ToastService.ts +19 -0
- package/src/styles/layout.css +64 -0
- package/src/styles/variables.css +85 -0
- package/src/typings.d.ts +4 -0
- package/src/utility/MockRouter/index.ts +45 -0
- package/src/utility/StorybookPanel/StorybookPanel.module.css +9 -0
- package/src/utility/StorybookPanel/index.tsx +25 -0
- package/src/utility/TestChangeHandler/TestChangeHandler.module.css +7 -0
- package/src/utility/TestChangeHandler/TestChangeHandler.spec.tsx +24 -0
- package/src/utility/TestChangeHandler/index.tsx +54 -0
- package/src/utility/create-app.tsx +29 -0
- package/src/utility/interfaces.ts +119 -0
- package/src/utility/prop-types.ts +67 -0
- package/tests/setupFilesAfterEnv.js +10 -0
- package/tsconfig.json +26 -0
- package/tsconfig.types.json +9 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { FormFieldComponentProps } from '@components/FormField';
|
|
2
|
+
import type { InputValue, Remote, SimpleObject } from '@utility/interfaces';
|
|
3
|
+
|
|
4
|
+
interface PanelOptions {
|
|
5
|
+
isScrollable?: boolean;
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/sort-type-union-intersection-members
|
|
7
|
+
size?: 'sm' | 'md' | 'lg';
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface FilterOptions {
|
|
11
|
+
data?: SimpleObject[] | string[];
|
|
12
|
+
label: string;
|
|
13
|
+
name: string;
|
|
14
|
+
props?: Record<string, unknown>;
|
|
15
|
+
remote?: Remote;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface FilterFieldProps extends FormFieldComponentProps {
|
|
19
|
+
data?: SimpleObject[] | string[];
|
|
20
|
+
extraProps?: Record<string, unknown>;
|
|
21
|
+
panelIndex?: number;
|
|
22
|
+
setPanelIndex?: React.Dispatch<React.SetStateAction<number>>;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface RenderSummaryArgs {
|
|
26
|
+
data?: SimpleObject[] | string[];
|
|
27
|
+
props?: Record<string, unknown>;
|
|
28
|
+
value?: InputValue;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface FilterField {
|
|
32
|
+
data?: SimpleObject[] | string[];
|
|
33
|
+
label: string;
|
|
34
|
+
name: string;
|
|
35
|
+
panelOptions?: PanelOptions | PanelOptions[];
|
|
36
|
+
props?: Record<string, unknown>;
|
|
37
|
+
remote?: Remote;
|
|
38
|
+
renderField: (props: FilterFieldProps) => React.ReactNode;
|
|
39
|
+
renderSummary?: (args: RenderSummaryArgs) => string;
|
|
40
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import userEvent from '@testing-library/user-event';
|
|
4
|
+
|
|
5
|
+
import TestChangeHandler from '@utility/TestChangeHandler';
|
|
6
|
+
|
|
7
|
+
import type { SimpleEventHandler, SimpleObject } from '@utility/interfaces';
|
|
8
|
+
|
|
9
|
+
import useAccessiblePanel from './useAccessiblePanel';
|
|
10
|
+
|
|
11
|
+
interface ComponentProps {
|
|
12
|
+
data?: SimpleObject[];
|
|
13
|
+
onChange?: SimpleEventHandler;
|
|
14
|
+
value?: (number | string)[] | number | string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const mockData = [
|
|
18
|
+
{
|
|
19
|
+
id: 'Lorem',
|
|
20
|
+
name: 'Lorem',
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: 'Ipsum',
|
|
24
|
+
name: 'Ipsum',
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
id: 'Dolor',
|
|
28
|
+
name: 'Dolor',
|
|
29
|
+
},
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
const Component: React.FunctionComponent<ComponentProps> = ({ data, onChange, value }) => {
|
|
33
|
+
const { handleKeyboard } = useAccessiblePanel({ data, name: 'lorem', onChange, value });
|
|
34
|
+
return <input onKeyDown={handleKeyboard} />;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
describe('useAccessiblePanel', () => {
|
|
38
|
+
it('should handle no data', () => {
|
|
39
|
+
const mockFn = jest.fn();
|
|
40
|
+
render(<Component onChange={mockFn} />);
|
|
41
|
+
|
|
42
|
+
userEvent.type(screen.getByRole('textbox'), '{ArrowDown}');
|
|
43
|
+
expect(mockFn).toHaveBeenCalledTimes(0);
|
|
44
|
+
|
|
45
|
+
userEvent.type(screen.getByRole('textbox'), '{ArrowUp}');
|
|
46
|
+
expect(mockFn).toHaveBeenCalledTimes(0);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('should get previous index', () => {
|
|
50
|
+
render(
|
|
51
|
+
<TestChangeHandler>
|
|
52
|
+
<Component data={mockData} />
|
|
53
|
+
</TestChangeHandler>
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
userEvent.type(screen.getByRole('textbox'), '{ArrowUp}');
|
|
57
|
+
expect(screen.getByTestId('test-change-handler-root')).toHaveTextContent('Dolor');
|
|
58
|
+
|
|
59
|
+
userEvent.type(screen.getByRole('textbox'), '{ArrowUp}');
|
|
60
|
+
expect(screen.getByTestId('test-change-handler-root')).toHaveTextContent('Ipsum');
|
|
61
|
+
|
|
62
|
+
userEvent.type(screen.getByRole('textbox'), '{ArrowUp}');
|
|
63
|
+
expect(screen.getByTestId('test-change-handler-root')).toHaveTextContent('Lorem');
|
|
64
|
+
|
|
65
|
+
userEvent.type(screen.getByRole('textbox'), '{ArrowUp}');
|
|
66
|
+
expect(screen.getByTestId('test-change-handler-root')).toHaveTextContent('Dolor');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('should get next index', () => {
|
|
70
|
+
render(
|
|
71
|
+
<TestChangeHandler>
|
|
72
|
+
<Component data={mockData} />
|
|
73
|
+
</TestChangeHandler>
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
userEvent.type(screen.getByRole('textbox'), '{ArrowDown}');
|
|
77
|
+
expect(screen.getByTestId('test-change-handler-root')).toHaveTextContent('Lorem');
|
|
78
|
+
|
|
79
|
+
userEvent.type(screen.getByRole('textbox'), '{ArrowDown}');
|
|
80
|
+
expect(screen.getByTestId('test-change-handler-root')).toHaveTextContent('Ipsum');
|
|
81
|
+
|
|
82
|
+
userEvent.type(screen.getByRole('textbox'), '{ArrowDown}');
|
|
83
|
+
expect(screen.getByTestId('test-change-handler-root')).toHaveTextContent('Dolor');
|
|
84
|
+
|
|
85
|
+
userEvent.type(screen.getByRole('textbox'), '{ArrowDown}');
|
|
86
|
+
expect(screen.getByTestId('test-change-handler-root')).toHaveTextContent('Lorem');
|
|
87
|
+
});
|
|
88
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { KeyboardEvent, KeyboardEventHandler } from 'react';
|
|
2
|
+
|
|
3
|
+
import { parseNumeric } from '@sqrzro/utility';
|
|
4
|
+
|
|
5
|
+
import type { SimpleEventHandler, SimpleObject } from '@utility/interfaces';
|
|
6
|
+
|
|
7
|
+
interface UseAccessiblePanelArgs {
|
|
8
|
+
data?: SimpleObject[];
|
|
9
|
+
name: string;
|
|
10
|
+
onChange?: SimpleEventHandler;
|
|
11
|
+
value?: (number | string)[] | number | string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface UseAccessiblePanelReturn<T> {
|
|
15
|
+
handleKeyboard: KeyboardEventHandler<T>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const getPreviousIndex = (index: number, limit: number): number => {
|
|
19
|
+
if (index <= 0) {
|
|
20
|
+
return limit - 1;
|
|
21
|
+
}
|
|
22
|
+
return index - 1;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const getNextIndex = (index: number, limit: number): number => {
|
|
26
|
+
if (index + 1 >= limit) {
|
|
27
|
+
return 0;
|
|
28
|
+
}
|
|
29
|
+
return index + 1;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const handleChange = <T>(
|
|
33
|
+
event: KeyboardEvent<T>,
|
|
34
|
+
name: string,
|
|
35
|
+
index: number,
|
|
36
|
+
data?: SimpleObject[],
|
|
37
|
+
onChange?: SimpleEventHandler
|
|
38
|
+
): void => {
|
|
39
|
+
event.preventDefault();
|
|
40
|
+
|
|
41
|
+
if (!onChange || !data || !data[index]) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
onChange({
|
|
46
|
+
item: data[index],
|
|
47
|
+
target: { name, value: data[index].id },
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const useAccessiblePanel = <T = HTMLButtonElement | HTMLInputElement>({
|
|
52
|
+
data,
|
|
53
|
+
name,
|
|
54
|
+
onChange,
|
|
55
|
+
value,
|
|
56
|
+
}: UseAccessiblePanelArgs): UseAccessiblePanelReturn<T> => {
|
|
57
|
+
const handleKeyboard = (event: KeyboardEvent<T>): void => {
|
|
58
|
+
const activeIndex = (data || []).findIndex((item) => parseNumeric(item.id) === value);
|
|
59
|
+
|
|
60
|
+
if (event.key === 'ArrowDown') {
|
|
61
|
+
const newIndex = getNextIndex(activeIndex, (data || []).length);
|
|
62
|
+
handleChange<T>(event, name, newIndex, data, onChange);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (event.key === 'ArrowUp') {
|
|
66
|
+
const newIndex = getPreviousIndex(activeIndex, (data || []).length);
|
|
67
|
+
handleChange<T>(event, name, newIndex, data, onChange);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
return { handleKeyboard };
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export default useAccessiblePanel;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { createContext, createElement, useContext } from 'react';
|
|
2
|
+
import merge from 'deepmerge';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
|
|
5
|
+
import type { NavigationObject } from '@utility/interfaces';
|
|
6
|
+
|
|
7
|
+
export interface Me {
|
|
8
|
+
name: string;
|
|
9
|
+
permissions?: string[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface AppContextObject {
|
|
13
|
+
auth: {
|
|
14
|
+
identifier?: string;
|
|
15
|
+
identifierLabel?: string;
|
|
16
|
+
tfa?: boolean;
|
|
17
|
+
} | null;
|
|
18
|
+
Logo: React.ComponentType<{ isReverse?: boolean }> | null;
|
|
19
|
+
me: Me | null;
|
|
20
|
+
name: string;
|
|
21
|
+
navigation: (NavigationObject | string)[];
|
|
22
|
+
paths: { api?: string; app?: string };
|
|
23
|
+
style: { brand?: string; layout?: string } | null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface Config extends Partial<AppContextObject> {
|
|
27
|
+
name: AppContextObject['name'];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const DEFAULTS: AppContextObject = {
|
|
31
|
+
auth: {},
|
|
32
|
+
Logo: null,
|
|
33
|
+
me: null,
|
|
34
|
+
name: '',
|
|
35
|
+
navigation: [],
|
|
36
|
+
paths: {},
|
|
37
|
+
style: {},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const AppContext = createContext(DEFAULTS);
|
|
41
|
+
|
|
42
|
+
interface AppContextProviderProps {
|
|
43
|
+
children: React.ReactNode;
|
|
44
|
+
value: Config;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const AppContextProvider: React.FunctionComponent<AppContextProviderProps> = ({
|
|
48
|
+
children,
|
|
49
|
+
value,
|
|
50
|
+
}) => createElement(AppContext.Provider, { value: merge(DEFAULTS, value) }, children);
|
|
51
|
+
|
|
52
|
+
AppContextProvider.propTypes = {
|
|
53
|
+
children: PropTypes.node.isRequired,
|
|
54
|
+
value: PropTypes.shape({
|
|
55
|
+
auth: PropTypes.shape({}),
|
|
56
|
+
Logo: PropTypes.func,
|
|
57
|
+
me: PropTypes.shape({
|
|
58
|
+
name: PropTypes.string.isRequired,
|
|
59
|
+
}).isRequired,
|
|
60
|
+
name: PropTypes.string.isRequired,
|
|
61
|
+
navigation: PropTypes.arrayOf(
|
|
62
|
+
PropTypes.oneOfType([
|
|
63
|
+
PropTypes.shape({
|
|
64
|
+
label: PropTypes.string.isRequired,
|
|
65
|
+
to: PropTypes.string,
|
|
66
|
+
}).isRequired,
|
|
67
|
+
PropTypes.string.isRequired,
|
|
68
|
+
]).isRequired
|
|
69
|
+
).isRequired,
|
|
70
|
+
paths: PropTypes.shape({}).isRequired,
|
|
71
|
+
style: PropTypes.shape({}),
|
|
72
|
+
}).isRequired,
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const useAppContext = (): AppContextObject => useContext(AppContext);
|
|
76
|
+
|
|
77
|
+
export default useAppContext;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import type { MutableRefObject } from 'react';
|
|
3
|
+
|
|
4
|
+
const useClickOutside = (): [
|
|
5
|
+
boolean,
|
|
6
|
+
(bool: boolean) => void,
|
|
7
|
+
MutableRefObject<HTMLDivElement | null>
|
|
8
|
+
] => {
|
|
9
|
+
let mounted = true;
|
|
10
|
+
|
|
11
|
+
const [isOpen, setIsOpen] = useState<boolean>(false);
|
|
12
|
+
const node = useRef<HTMLDivElement>(null);
|
|
13
|
+
|
|
14
|
+
const handleClickOutside = (event: Event): void => {
|
|
15
|
+
if (node.current?.contains(event.target as HTMLDivElement)) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
setTimeout(() => {
|
|
19
|
+
if (mounted) {
|
|
20
|
+
setIsOpen(false);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const handleEscapeKey = (event: KeyboardEvent): void => {
|
|
26
|
+
if (event.key === 'Escape') {
|
|
27
|
+
setTimeout(() => {
|
|
28
|
+
if (mounted) {
|
|
29
|
+
setIsOpen(false);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
document.addEventListener('click', handleClickOutside);
|
|
37
|
+
document.addEventListener('keydown', handleEscapeKey);
|
|
38
|
+
|
|
39
|
+
return (): void => {
|
|
40
|
+
mounted = false;
|
|
41
|
+
document.removeEventListener('click', handleClickOutside);
|
|
42
|
+
document.removeEventListener('keydown', handleEscapeKey);
|
|
43
|
+
};
|
|
44
|
+
}, []);
|
|
45
|
+
|
|
46
|
+
return [isOpen, (bool: boolean): void => setIsOpen(bool), node];
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export default useClickOutside;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createElement, useCallback, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import ConnectedList from '@components/ConnectedList';
|
|
4
|
+
import type { ConnectedRepeaterElementProps, ListFunctions } from '@core/ConnectedRepeater';
|
|
5
|
+
|
|
6
|
+
interface UseConnectedListReturn extends ListFunctions {
|
|
7
|
+
ConnectedList: React.FunctionComponent;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const useConnectedList = (): UseConnectedListReturn => {
|
|
11
|
+
const [listFunctions, setListFunctions] = useState<ListFunctions>({ reloadList: () => null });
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
ConnectedList: useCallback(
|
|
15
|
+
(props) =>
|
|
16
|
+
createElement(ConnectedList, {
|
|
17
|
+
...props,
|
|
18
|
+
setFunctions: (fnc: ListFunctions) => setListFunctions(fnc),
|
|
19
|
+
} as ConnectedRepeaterElementProps),
|
|
20
|
+
[]
|
|
21
|
+
),
|
|
22
|
+
reloadList: listFunctions.reloadList,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export default useConnectedList;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { useRouter } from 'next/router';
|
|
3
|
+
|
|
4
|
+
import { parseSearch } from '@sqrzro/utility';
|
|
5
|
+
|
|
6
|
+
import FilterService from '@services/FilterService';
|
|
7
|
+
import type { FilterMap, FilterOptions } from '@services/FilterService';
|
|
8
|
+
|
|
9
|
+
const useFilters = (options?: FilterOptions): [FilterMap, (data: FilterMap) => void] => {
|
|
10
|
+
const router = useRouter();
|
|
11
|
+
const [filters, setFilters] = useState<FilterMap>(
|
|
12
|
+
FilterService.parseQuery(parseSearch(window.location.search))
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
setFilters(FilterService.parseQuery(parseSearch(window.location.search), options));
|
|
17
|
+
}, [window.location.search]);
|
|
18
|
+
|
|
19
|
+
const applyFilters = (data: FilterMap): void => {
|
|
20
|
+
void router.push(FilterService.makeUrl(data));
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
return [filters, applyFilters];
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export default useFilters;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { renderHook } from '@testing-library/react-hooks';
|
|
2
|
+
import { waitFor } from '@testing-library/react';
|
|
3
|
+
|
|
4
|
+
import { ApiService } from '@sqrzro/utility';
|
|
5
|
+
|
|
6
|
+
import ToastService from '@services/ToastService';
|
|
7
|
+
|
|
8
|
+
import useForm from './useForm';
|
|
9
|
+
|
|
10
|
+
jest.mock('@services/ToastService', () => ({
|
|
11
|
+
success: jest.fn(),
|
|
12
|
+
error: jest.fn(),
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
const mockErrorResponse = {
|
|
16
|
+
data: { errors: {} },
|
|
17
|
+
headers: new Headers(),
|
|
18
|
+
status: 422,
|
|
19
|
+
url: 'lorem',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
describe('useForm', () => {
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
(ToastService.error as jest.Mock).mockClear();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('should handle default submit success', async () => {
|
|
28
|
+
// @ts-expect-error APIResponse not being available
|
|
29
|
+
jest.spyOn(ApiService, 'request').mockImplementation(() => ({
|
|
30
|
+
data: { token: 'lorem' },
|
|
31
|
+
}));
|
|
32
|
+
|
|
33
|
+
const mockFn = jest.fn();
|
|
34
|
+
const { result } = renderHook(() => useForm({ url: 'lorem', formData: {} }));
|
|
35
|
+
|
|
36
|
+
await waitFor(() => {
|
|
37
|
+
result.current.handleSubmit();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
expect(mockFn).toHaveBeenCalledTimes(0);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('should handle submit success', async () => {
|
|
44
|
+
// @ts-expect-error APIResponse not being available
|
|
45
|
+
jest.spyOn(ApiService, 'request').mockImplementation(() => ({
|
|
46
|
+
data: { token: 'lorem' },
|
|
47
|
+
}));
|
|
48
|
+
|
|
49
|
+
const mockFn = jest.fn();
|
|
50
|
+
const { result } = renderHook(() =>
|
|
51
|
+
useForm({ url: 'lorem', formData: {}, onSubmitSuccess: mockFn })
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
await waitFor(() => {
|
|
55
|
+
result.current.handleSubmit();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
expect(mockFn).toHaveBeenCalledTimes(1);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('should handle default submit error', async () => {
|
|
62
|
+
jest.spyOn(ApiService, 'request').mockImplementation(() => {
|
|
63
|
+
throw new Error('lorem');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
const mockFn = jest.fn();
|
|
67
|
+
const { result } = renderHook(() => useForm({ url: 'lorem', formData: {} }));
|
|
68
|
+
|
|
69
|
+
await waitFor(() => {
|
|
70
|
+
result.current.handleSubmit();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
expect(mockFn).toHaveBeenCalledTimes(0);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('should handle submit error', async () => {
|
|
77
|
+
jest.spyOn(ApiService, 'request').mockImplementation(() => {
|
|
78
|
+
throw new Error('lorem');
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const mockFn = jest.fn();
|
|
82
|
+
const { result } = renderHook(() =>
|
|
83
|
+
useForm({ url: 'lorem', formData: {}, onSubmitError: mockFn })
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
await waitFor(() => {
|
|
87
|
+
result.current.handleSubmit();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
expect(mockFn).toHaveBeenCalledTimes(1);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('should toast error message', async () => {
|
|
94
|
+
jest.spyOn(ApiService, 'request').mockImplementation(() => {
|
|
95
|
+
throw new ApiService.ApiValidationError(mockErrorResponse);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const { result } = renderHook(() =>
|
|
99
|
+
useForm({ url: 'lorem', formData: {}, errorMessage: 'error lorem' })
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
await waitFor(() => {
|
|
103
|
+
result.current.handleSubmit();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
expect(ToastService.error).toHaveBeenCalledTimes(1);
|
|
107
|
+
expect(ToastService.error).toHaveBeenLastCalledWith('error lorem');
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('should toast with default error message', async () => {
|
|
111
|
+
jest.spyOn(ApiService, 'request').mockImplementation(() => {
|
|
112
|
+
throw new ApiService.ApiValidationError(mockErrorResponse);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const { result } = renderHook(() => useForm({ url: 'lorem', formData: {} }));
|
|
116
|
+
|
|
117
|
+
await waitFor(() => {
|
|
118
|
+
result.current.handleSubmit();
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
expect(ToastService.error).toHaveBeenCalledTimes(1);
|
|
122
|
+
expect(ToastService.error).toHaveBeenLastCalledWith(
|
|
123
|
+
'Could not save. Please check the form.'
|
|
124
|
+
);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { ApiService } from '@sqrzro/utility';
|
|
4
|
+
|
|
5
|
+
import ToastService from '@services/ToastService';
|
|
6
|
+
import type { InputValue } from '@utility/interfaces';
|
|
7
|
+
|
|
8
|
+
interface ApiResponseObject<T = Record<string, unknown>> {
|
|
9
|
+
data: T & { errors?: Record<string, [string]> };
|
|
10
|
+
headers: Headers;
|
|
11
|
+
status: number;
|
|
12
|
+
url: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface UseFormArgs {
|
|
16
|
+
errorMessage?: string | false;
|
|
17
|
+
formData: Record<string, InputValue>;
|
|
18
|
+
method?: 'get' | 'patch' | 'post';
|
|
19
|
+
successMessage?: string | false;
|
|
20
|
+
url: string;
|
|
21
|
+
onSubmitSuccess?: (response: ApiResponseObject) => void;
|
|
22
|
+
onSubmitError?: (err?: Error) => void;
|
|
23
|
+
transformRequest?: (data: Record<string, InputValue>) => Record<string, InputValue>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface UseFormReturn {
|
|
27
|
+
errors: Record<string, string>;
|
|
28
|
+
isLoading: boolean;
|
|
29
|
+
handleSubmit: () => void;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const useForm = ({
|
|
33
|
+
errorMessage,
|
|
34
|
+
formData,
|
|
35
|
+
method = 'post',
|
|
36
|
+
successMessage,
|
|
37
|
+
url,
|
|
38
|
+
onSubmitSuccess = (): void => void 0,
|
|
39
|
+
onSubmitError = (): void => void 0,
|
|
40
|
+
transformRequest = (data): Record<string, InputValue> => data,
|
|
41
|
+
}: UseFormArgs): UseFormReturn => {
|
|
42
|
+
const [errors, setErrors] = useState<Record<string, string>>({});
|
|
43
|
+
const [isLoading, setIsLoading] = useState<boolean>(false);
|
|
44
|
+
|
|
45
|
+
const handleSubmitSuccess = (response: ApiResponseObject): void => {
|
|
46
|
+
setIsLoading(false);
|
|
47
|
+
|
|
48
|
+
if (successMessage !== false) {
|
|
49
|
+
ToastService.success(successMessage || 'Saved successfully');
|
|
50
|
+
}
|
|
51
|
+
onSubmitSuccess(response);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const handleSubmitError = (error: unknown): void => {
|
|
55
|
+
/*
|
|
56
|
+
* This will almost certainly never happen in reality, but because the catch block in the
|
|
57
|
+
* handleSubmit function can only expect an unknown type, we can check it's an Error here.
|
|
58
|
+
* This can be safely ignored by coverage.
|
|
59
|
+
*/
|
|
60
|
+
/* istanbul ignore next */
|
|
61
|
+
if (!(error instanceof Error)) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
setIsLoading(false);
|
|
66
|
+
onSubmitError(error);
|
|
67
|
+
|
|
68
|
+
/*
|
|
69
|
+
* If the `err` is not a `ApiValidationError`, `getErrorsFromResponse` will throw it again.
|
|
70
|
+
* For this reason, it needs to be in a try/catch block, and a general error message should
|
|
71
|
+
* be toasted if the error was not validation.
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
setErrors(ApiService.getErrorsFromResponse(error));
|
|
76
|
+
if (errorMessage !== false) {
|
|
77
|
+
ToastService.error(errorMessage || 'Could not save. Please check the form.');
|
|
78
|
+
}
|
|
79
|
+
} catch (err) {
|
|
80
|
+
ToastService.error("Something's gone wrong. Please try again.");
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const handleSubmit = async (): Promise<void> => {
|
|
85
|
+
setErrors({});
|
|
86
|
+
setIsLoading(true);
|
|
87
|
+
|
|
88
|
+
try {
|
|
89
|
+
const response = await ApiService.request(method, url, transformRequest(formData));
|
|
90
|
+
handleSubmitSuccess(response);
|
|
91
|
+
} catch (err: unknown) {
|
|
92
|
+
handleSubmitError(err);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
return { errors, isLoading, handleSubmit };
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export default useForm;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { renderHook } from '@testing-library/react-hooks';
|
|
2
|
+
import { waitFor } from '@testing-library/react';
|
|
3
|
+
|
|
4
|
+
import useFormData from './useFormData';
|
|
5
|
+
|
|
6
|
+
describe('useFormData', () => {
|
|
7
|
+
it('should have fields', () => {
|
|
8
|
+
const { result } = renderHook(() => useFormData({ data: { lorem: 1 }, fields: ['lorem'] }));
|
|
9
|
+
expect(result.current[0]).toEqual({ lorem: 1 });
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('should handle no fields', () => {
|
|
13
|
+
const { result } = renderHook(() => useFormData({ data: { lorem: 1 } }));
|
|
14
|
+
expect(result.current[0]).toEqual({});
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('should have defaults', () => {
|
|
18
|
+
const { result } = renderHook(() =>
|
|
19
|
+
useFormData({ defaults: { lorem: 1 }, data: { lorem: 2 }, fields: ['lorem'] })
|
|
20
|
+
);
|
|
21
|
+
expect(result.current[0]).toEqual({ lorem: 2 });
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should handle only defaults', () => {
|
|
25
|
+
const { result } = renderHook(() =>
|
|
26
|
+
useFormData({ defaults: { lorem: 1 }, fields: ['lorem'] })
|
|
27
|
+
);
|
|
28
|
+
expect(result.current[0]).toEqual({ lorem: 1 });
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('should set data', async () => {
|
|
32
|
+
const { result } = renderHook(() => useFormData({ data: { lorem: 1 }, fields: ['lorem'] }));
|
|
33
|
+
|
|
34
|
+
await waitFor(() => {
|
|
35
|
+
result.current[1]('lorem', 2);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
expect(result.current[0]).toEqual({ lorem: 2 });
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import type { InputValue } from '@utility/interfaces';
|
|
4
|
+
|
|
5
|
+
import { getFromObject } from '@sqrzro/utility';
|
|
6
|
+
|
|
7
|
+
export interface FormDataArgs {
|
|
8
|
+
data?: Record<string, InputValue>;
|
|
9
|
+
defaults?: Record<string, InputValue>;
|
|
10
|
+
fields?: string[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type FormDataReturn = [Record<string, InputValue>, (key: string, value: InputValue) => void];
|
|
14
|
+
|
|
15
|
+
const useFormData = ({ data, defaults, fields }: FormDataArgs): FormDataReturn => {
|
|
16
|
+
const [fData, setFData] = useState(
|
|
17
|
+
getFromObject({ ...(defaults || {}), ...(data || {}) }, fields || [])
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
const setFormData = (key: string, value: InputValue): void => {
|
|
21
|
+
setFData({ ...fData, [key]: value });
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
return [fData, setFormData];
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export default useFormData;
|