saleor-dashboard/src/components/Form/Form.tsx

68 lines
1.4 KiB
TypeScript
Raw Normal View History

import useForm, { SubmitPromise, UseFormResult } from "@saleor/hooks/useForm";
import React from "react";
2019-08-09 11:14:35 +00:00
import { FormId } from "./types";
Exit dirty form (#1816) * Add Exit form prompt component and change some minor styles in other components to match * Add Exit form prompt provider * Adjust generic form and useform hook to allow using exit form prompt provider * Add exit form prompt provider to index * wip * Fix types * Fix styling * Fix types * Revert warehouse details refactor * Add handling of edge cases to exit prompt * Refactor, add comments, fix some types * Refactor after exit form dialog name change * fix types * Fixes after review * Add default value for useform prop opts so the app doesn't crash * Add missing category prop to getting initial data for category details form * Add exit dialog to everywhere WIP (#1600) * Add Exit form prompt component and change some minor styles in other components to match * Add Exit form prompt provider * Adjust generic form and useform hook to allow using exit form prompt provider * Add exit form prompt provider to index * wip * Fix types * Fix styling * Fix types * Revert warehouse details refactor * Add handling of edge cases to exit prompt * Refactor, add comments, fix some types * Refactor after exit form dialog name change * fix types * Add CommonUseFormResultWithHandlers type for later use and refactor handleFormSubmit util * Refactor login form not to use custom form since it doesn't need to * Add exit form dialog to order refund page * Add exit form dialog to order return page * Add exit form dialog to order order settings page * Add exit form dialog to product variant page * Add exit form dialog to product create page * Add exit form dialog to product update page * Add exit form dialog to product variant create page * Fix confirm leave prop passing in generic Form * Add util function to handle for submit to extract errors * Add confirmLeave prop to generic forms * Move handleChange for custom forms to useForm * Add exit dialog to more forms * Add extract mutation errors util function * Add extracting errors to submit functions that use metadata create handler * Fix typo * Add missing category prop to getting initial data for category details form * Fix types * wip * wip * wip * wip * Fix types & refactor * Fix types & refactor * Fix typescript * Fix unmatching tag * Fixes * Add handling of multiple forms at once to exit dirty form provider * Change all usages of ExitFormDialogContext to designated hook * wip * wip * wip * Fix types wip * Fix types * Remove console logs * Add isSubmitting prop to exit form dialog in order to avoid enabling exit dialog while submit is still in progresS * Replace handleSubmit global util with a hook to use exit form dialog props inside * Move useHandleSubmit to general hooks dir, update imports * Small fixes * Update snapshots * Fix types * Small fixes due to extensive rebase * Update package lock * Fixes after rebase * Remove exit form from customer address dialog * Fix types and update messages * Fix types * Change imports names * Refactor * Remove unnecessary console.log * Update types, snapshots. etc after rebase
2022-02-01 09:58:06 +00:00
export type CheckIfSaveIsDisabledFnType<T> = (data: T) => boolean;
Exit dirty form (#1816) * Add Exit form prompt component and change some minor styles in other components to match * Add Exit form prompt provider * Adjust generic form and useform hook to allow using exit form prompt provider * Add exit form prompt provider to index * wip * Fix types * Fix styling * Fix types * Revert warehouse details refactor * Add handling of edge cases to exit prompt * Refactor, add comments, fix some types * Refactor after exit form dialog name change * fix types * Fixes after review * Add default value for useform prop opts so the app doesn't crash * Add missing category prop to getting initial data for category details form * Add exit dialog to everywhere WIP (#1600) * Add Exit form prompt component and change some minor styles in other components to match * Add Exit form prompt provider * Adjust generic form and useform hook to allow using exit form prompt provider * Add exit form prompt provider to index * wip * Fix types * Fix styling * Fix types * Revert warehouse details refactor * Add handling of edge cases to exit prompt * Refactor, add comments, fix some types * Refactor after exit form dialog name change * fix types * Add CommonUseFormResultWithHandlers type for later use and refactor handleFormSubmit util * Refactor login form not to use custom form since it doesn't need to * Add exit form dialog to order refund page * Add exit form dialog to order return page * Add exit form dialog to order order settings page * Add exit form dialog to product variant page * Add exit form dialog to product create page * Add exit form dialog to product update page * Add exit form dialog to product variant create page * Fix confirm leave prop passing in generic Form * Add util function to handle for submit to extract errors * Add confirmLeave prop to generic forms * Move handleChange for custom forms to useForm * Add exit dialog to more forms * Add extract mutation errors util function * Add extracting errors to submit functions that use metadata create handler * Fix typo * Add missing category prop to getting initial data for category details form * Fix types * wip * wip * wip * wip * Fix types & refactor * Fix types & refactor * Fix typescript * Fix unmatching tag * Fixes * Add handling of multiple forms at once to exit dirty form provider * Change all usages of ExitFormDialogContext to designated hook * wip * wip * wip * Fix types wip * Fix types * Remove console logs * Add isSubmitting prop to exit form dialog in order to avoid enabling exit dialog while submit is still in progresS * Replace handleSubmit global util with a hook to use exit form dialog props inside * Move useHandleSubmit to general hooks dir, update imports * Small fixes * Update snapshots * Fix types * Small fixes due to extensive rebase * Update package lock * Fixes after rebase * Remove exit form from customer address dialog * Fix types and update messages * Fix types * Change imports names * Refactor * Remove unnecessary console.log * Update types, snapshots. etc after rebase
2022-02-01 09:58:06 +00:00
export interface FormProps<TData, TErrors>
2021-11-23 09:03:07 +00:00
extends Omit<React.HTMLProps<HTMLFormElement>, "onSubmit"> {
Exit dirty form (#1816) * Add Exit form prompt component and change some minor styles in other components to match * Add Exit form prompt provider * Adjust generic form and useform hook to allow using exit form prompt provider * Add exit form prompt provider to index * wip * Fix types * Fix styling * Fix types * Revert warehouse details refactor * Add handling of edge cases to exit prompt * Refactor, add comments, fix some types * Refactor after exit form dialog name change * fix types * Fixes after review * Add default value for useform prop opts so the app doesn't crash * Add missing category prop to getting initial data for category details form * Add exit dialog to everywhere WIP (#1600) * Add Exit form prompt component and change some minor styles in other components to match * Add Exit form prompt provider * Adjust generic form and useform hook to allow using exit form prompt provider * Add exit form prompt provider to index * wip * Fix types * Fix styling * Fix types * Revert warehouse details refactor * Add handling of edge cases to exit prompt * Refactor, add comments, fix some types * Refactor after exit form dialog name change * fix types * Add CommonUseFormResultWithHandlers type for later use and refactor handleFormSubmit util * Refactor login form not to use custom form since it doesn't need to * Add exit form dialog to order refund page * Add exit form dialog to order return page * Add exit form dialog to order order settings page * Add exit form dialog to product variant page * Add exit form dialog to product create page * Add exit form dialog to product update page * Add exit form dialog to product variant create page * Fix confirm leave prop passing in generic Form * Add util function to handle for submit to extract errors * Add confirmLeave prop to generic forms * Move handleChange for custom forms to useForm * Add exit dialog to more forms * Add extract mutation errors util function * Add extracting errors to submit functions that use metadata create handler * Fix typo * Add missing category prop to getting initial data for category details form * Fix types * wip * wip * wip * wip * Fix types & refactor * Fix types & refactor * Fix typescript * Fix unmatching tag * Fixes * Add handling of multiple forms at once to exit dirty form provider * Change all usages of ExitFormDialogContext to designated hook * wip * wip * wip * Fix types wip * Fix types * Remove console logs * Add isSubmitting prop to exit form dialog in order to avoid enabling exit dialog while submit is still in progresS * Replace handleSubmit global util with a hook to use exit form dialog props inside * Move useHandleSubmit to general hooks dir, update imports * Small fixes * Update snapshots * Fix types * Small fixes due to extensive rebase * Update package lock * Fixes after rebase * Remove exit form from customer address dialog * Fix types and update messages * Fix types * Change imports names * Refactor * Remove unnecessary console.log * Update types, snapshots. etc after rebase
2022-02-01 09:58:06 +00:00
children: (props: UseFormResult<TData>) => React.ReactNode;
2019-08-09 11:14:35 +00:00
confirmLeave?: boolean;
Exit dirty form (#1816) * Add Exit form prompt component and change some minor styles in other components to match * Add Exit form prompt provider * Adjust generic form and useform hook to allow using exit form prompt provider * Add exit form prompt provider to index * wip * Fix types * Fix styling * Fix types * Revert warehouse details refactor * Add handling of edge cases to exit prompt * Refactor, add comments, fix some types * Refactor after exit form dialog name change * fix types * Fixes after review * Add default value for useform prop opts so the app doesn't crash * Add missing category prop to getting initial data for category details form * Add exit dialog to everywhere WIP (#1600) * Add Exit form prompt component and change some minor styles in other components to match * Add Exit form prompt provider * Adjust generic form and useform hook to allow using exit form prompt provider * Add exit form prompt provider to index * wip * Fix types * Fix styling * Fix types * Revert warehouse details refactor * Add handling of edge cases to exit prompt * Refactor, add comments, fix some types * Refactor after exit form dialog name change * fix types * Add CommonUseFormResultWithHandlers type for later use and refactor handleFormSubmit util * Refactor login form not to use custom form since it doesn't need to * Add exit form dialog to order refund page * Add exit form dialog to order return page * Add exit form dialog to order order settings page * Add exit form dialog to product variant page * Add exit form dialog to product create page * Add exit form dialog to product update page * Add exit form dialog to product variant create page * Fix confirm leave prop passing in generic Form * Add util function to handle for submit to extract errors * Add confirmLeave prop to generic forms * Move handleChange for custom forms to useForm * Add exit dialog to more forms * Add extract mutation errors util function * Add extracting errors to submit functions that use metadata create handler * Fix typo * Add missing category prop to getting initial data for category details form * Fix types * wip * wip * wip * wip * Fix types & refactor * Fix types & refactor * Fix typescript * Fix unmatching tag * Fixes * Add handling of multiple forms at once to exit dirty form provider * Change all usages of ExitFormDialogContext to designated hook * wip * wip * wip * Fix types wip * Fix types * Remove console logs * Add isSubmitting prop to exit form dialog in order to avoid enabling exit dialog while submit is still in progresS * Replace handleSubmit global util with a hook to use exit form dialog props inside * Move useHandleSubmit to general hooks dir, update imports * Small fixes * Update snapshots * Fix types * Small fixes due to extensive rebase * Update package lock * Fixes after rebase * Remove exit form from customer address dialog * Fix types and update messages * Fix types * Change imports names * Refactor * Remove unnecessary console.log * Update types, snapshots. etc after rebase
2022-02-01 09:58:06 +00:00
initial?: TData;
2019-06-19 14:40:52 +00:00
resetOnSubmit?: boolean;
Exit dirty form (#1816) * Add Exit form prompt component and change some minor styles in other components to match * Add Exit form prompt provider * Adjust generic form and useform hook to allow using exit form prompt provider * Add exit form prompt provider to index * wip * Fix types * Fix styling * Fix types * Revert warehouse details refactor * Add handling of edge cases to exit prompt * Refactor, add comments, fix some types * Refactor after exit form dialog name change * fix types * Fixes after review * Add default value for useform prop opts so the app doesn't crash * Add missing category prop to getting initial data for category details form * Add exit dialog to everywhere WIP (#1600) * Add Exit form prompt component and change some minor styles in other components to match * Add Exit form prompt provider * Adjust generic form and useform hook to allow using exit form prompt provider * Add exit form prompt provider to index * wip * Fix types * Fix styling * Fix types * Revert warehouse details refactor * Add handling of edge cases to exit prompt * Refactor, add comments, fix some types * Refactor after exit form dialog name change * fix types * Add CommonUseFormResultWithHandlers type for later use and refactor handleFormSubmit util * Refactor login form not to use custom form since it doesn't need to * Add exit form dialog to order refund page * Add exit form dialog to order return page * Add exit form dialog to order order settings page * Add exit form dialog to product variant page * Add exit form dialog to product create page * Add exit form dialog to product update page * Add exit form dialog to product variant create page * Fix confirm leave prop passing in generic Form * Add util function to handle for submit to extract errors * Add confirmLeave prop to generic forms * Move handleChange for custom forms to useForm * Add exit dialog to more forms * Add extract mutation errors util function * Add extracting errors to submit functions that use metadata create handler * Fix typo * Add missing category prop to getting initial data for category details form * Fix types * wip * wip * wip * wip * Fix types & refactor * Fix types & refactor * Fix typescript * Fix unmatching tag * Fixes * Add handling of multiple forms at once to exit dirty form provider * Change all usages of ExitFormDialogContext to designated hook * wip * wip * wip * Fix types wip * Fix types * Remove console logs * Add isSubmitting prop to exit form dialog in order to avoid enabling exit dialog while submit is still in progresS * Replace handleSubmit global util with a hook to use exit form dialog props inside * Move useHandleSubmit to general hooks dir, update imports * Small fixes * Update snapshots * Fix types * Small fixes due to extensive rebase * Update package lock * Fixes after rebase * Remove exit form from customer address dialog * Fix types and update messages * Fix types * Change imports names * Refactor * Remove unnecessary console.log * Update types, snapshots. etc after rebase
2022-02-01 09:58:06 +00:00
onSubmit?: (data: TData) => SubmitPromise<TErrors[]> | void;
formId?: FormId;
checkIfSaveIsDisabled?: CheckIfSaveIsDisabledFnType<TData>;
🦄 Simple taxes (#2072) * Tax configuration - implement channels view (#2048) * Add channels view * Fix channels view import * Remove legacy stories references * Fix link in configuration * Update snapshots * Remove sample checkboxes props * Disable hover in country exceptions * Update snapshots * Extract country exception rows to seperate component * Extract components to seperate files * Remove duplicated section name * Remove backlink * Add translations to section names * Extract messages * Add ListItemLink component * Replace navigator with link in TaxChannelsMenu * Fix horizontal scroll in TaxChannelsMenu * Change codegen to build from custom schema * Build types * Update fragments * Add fixtures * Change any to proper types * Add story for tax channels page * Replace MUI Skeleton with Saleor Skeleton * Change clsx import to classnames * Fix checkboxes shadows in settings card * Update IDs in fixtures * Fix offset in TaxChannelsMenu * Update snapshots * Remove any from TaxSettings * Fix todos * Change relative marginLeft to before pseudoelement * Extract styles to seperate files * Change folder structure * Extract redirect logic to custom hook * Update snapshots * Fix comment * Add early return in channels view * Tax configuration - implement countries view (#2053) * Add channels view * Remove sample checkboxes props * Disable hover in country exceptions * Extract country exception rows to seperate component * Extract components to seperate files * Remove duplicated section name * Remove backlink * Add translations to section names * Replace navigator with link in TaxChannelsMenu * Fix horizontal scroll in TaxChannelsMenu * Change any to proper types * Add story for tax channels page * Replace MUI Skeleton with Saleor Skeleton * Change clsx import to classnames * Fix checkboxes shadows in settings card * Update IDs in fixtures * Fix offset in TaxChannelsMenu * Remove any from TaxSettings * Add countries list view * Add TaxCountryMenu component * Add CountryList page * Change channels menu rows height * Change countries menu rows height * Add TaxInput component * Add tax classes rates to countries page * Fix search input padding * Add minmax to TaxInput * Add searching through tax class rates * Extract messages * Add better handlers * Add fullWidth to TaxInput * Specify type for TaxInputs * Remove spinboxes on firefox * Remove custom spinboxes * Remove maxHeight from menu rows * Post-rebase fix * Change setter to formchagne * Add TaxConfiguration fragment * Add isDefault field to taxClass * Add fixtures * Shape data * Replace useEffect with useTaxUrlRedirect * Fix country names in menu * Add country page story * Add early return in countries view * Unify loading states between channels and countries pages * Handle special chars and case insensitiveness in local search * Replace navigate function with ListItemLink * Move styles to seperate file * Move styles to seperate file * Migrate to strict null checks * Remove unnecessary optional chaining * Change overflow scroll to Y only * Add useMemo on finding selected country * Add useMemo on local search * Translate labels in page tabs * Change url from /taxes/classes to /taxes/tax-classes * Remove capitalization from strings * Extract messages * Bump macaw to 0.6.2 * Update snapshots * Add spinboxes explanation comment * Handle empty state * Add tax classes view (#2093) * Add TaxClass fragment * Build types * Add tax classes to fixtures * Add tax classes view * wip Add tax classes page * Add tax classes menu * Add TaxRate fragment * Extract logic * Handle loading state & add story * Extract messages * Update snapshots * Change schema building from schema back to introspection * Update schema * Update fragments * Build types * Update fixtures * Reshape data * Move styles to seperate file * Use getById * Add explicit undefined * Comment out unfinished modal stories * Update snapshots * Taxes - add API calls in channels view (#2106) * Build types * Add TaxRate fragment * Update snapshots * Add taxConfigurationList query * Add taxCountriesList query * Add TaxClassesList query * Rename TaxConfigurationsList query * Handle empty state * Fix types post-rebase * Add form to TaxChannelsPage * wip Add dialog for handling country exceptions * wip Fix dialog url * wip Add update exceptions handlers * Add dialog story * Fix type errors * Add mutation support * Fix types in story * Add transition state to submit button * Add notifier * Extract messages * Remove unused import * Add backlink in savebar * Update snapshots * Fix link in navigation * Update snapshots * Remove message from tax config error fragment * Add hook description * Use useStateFromProps * Remove error handling * Improve url & path function names * Use theme.spacing in TaxCountryDialog styles * Remove redundant key modification * Revert "Use useStateFromProps" This reverts commit d3c68b04701cf935e917d7baa3ed1361ca3446d5. * Move initial map to parent & add open dependency to countries state * Use useModalDialogOpen * Fix state update * Remove scrolls & add ellipsis in side menu * Center checkboxes * Update snapshots * Add fake div for list alignment * Trigger deployment * Close modal on submit * Remove divider on last ListItem * Align add country button * Wrap grid child in div to avoid card stretching * Update snapshots * Trigger changes in add/delete exceptions * Trigger change on expcetion checkboxes * Add trailing commas * Connect countries view to API (#2178) * Add empty states * Update countries view urls * Remove unused import * Add country modal to countries view * Update schema * Implement country view mutations & error fragments * Implement tax class update mutation * Add sidebar temporary state for new configs * Remove unused imports * Wrap in form * Add savebar & fix search * Update schema * Add form wrapper * Fix types * Extract messages * Bump macaw * Update snapshots * Fix comma dangles * Update snapshots * Notify about mutation success * Add logic for mixing current and new rates * Workaround for sending null rates * Fix filling form with correct data after submitting * Handle deleting configuration * Fix selected banner * Remove leftover comment * Add handler for country configuration delete * Trigger deployment * Clean up useEffects causing infinite render loops * Sort countries from api by name * Fix card bottom padding * Remove bottom divider & fix padding * Remove scroll wrapper in side menu * Update snapshots * Remove scroll wrapper from tax classes menu * Update snapshots * Refresh form to initial onSubmit * Revert "Refresh form to initial onSubmit" This reverts commit 42414237d35086da63f4aa088c8072411429b1d8. * Allow only 3 decimal characters in tax inputs * Update snapshots * Update schema * Update types * Change logic from default tax class to null class * Fix sorting * Send empty country rates as nulls in mutation * Extract messages * Update lockfile * Update schema * Drop default tax classes * Update snapshots * Post-rebase fixes * Connect tax classes view to API (#2334) * Add mutations * Handle empty state * Wrap page in form * Update stories * Build types * Handle tax class delete * Handle update tax class * Update stories * Handle tax class change name * Add mutation state to savebar * Handle creating new tax classes * Extract messages * Specify type * Update stories * Sort rates * Fix skeleton rendering * Remove placeholders * Fix skeleton rendering on country list * Update snapshots * Change initial pagination to 100 * Disallow creating multiple new tax classes * Disallow creating multiple country configurations * Fix messages * Autofocus on new tax class name * Add country name to header * Temporarily comment out broken code in tax channels * Update snapshots * Update snapshots post-rebase * Add tax strategies & assigning tax classes (#2369) * Update fragments * Add optional merging in useForm * Handle tax strategies * Update snapshots * Update fixtures * Extract messages * Remove unused shop query fields * Fix breaking bug when fetchMore is used in non-searchable SingleAutocompleteSelectFields * Migrate product types to tax classes * Add tax classes to shipping methods * Use encapsulated logic in product types * Fix product type stories * Fix shipping fixtures * Fix product type type mismatch * Fix shipping stories * Fix product type fixtures * Fix mismatching types * Extract messages * Update snapshots * Update snapshots * Fix comment * Drop deprecated graphql fields * Replace tax types with tax classes in product create view * Replace tax types with tax classes in product update view * Fix tests, stories, fixtures * Extract messages * Update snapshots * Move status messages to commonStatusMessages * Handle empty array case in tax class change handler * Reuse messages * Simple taxes bugfixes (#2395) * Fix tax channels menu - dense layout * Change view names to fit convention * Fix per country exceptions in tax channels view * Fix skeleton rendering on tax countries card title * Filter out existing countries from modal * Update snapshots * Fix deleting country configuration * Disallow negative values in tax inputs * Handle empty tax classes view * Allow empty options in shipping & product types views tax class assignment field * Modify undefined rates in tax classes view * Update macaw-ui * Fix UI on channels view * Fix UI on countries view * Fix UI on countries view * Align tax class rate label to the right * Updaste snapshots * Extract messages * Fix adding rates on new tax class * Fix key errors * Update schema * Build types * Allow empty rates in taxClassUpdate mutation * Extract tax channels change country function as a handler * Deprecate useStateFromProps * Change useStateFromProps to useStateUpdate * Fix dividers * Delete delete icon on new tax classes * Update snapshots * Update lockfile * Update macaw to 0.6.6 * Update snapshots * Specify type of input in country change handler * Extract autofocus logic to custom hook * Replace alternative with switch statement * Extract country exclusion logic from JSX * Update lockfile * Update lockfile * Trigger deployment * Fix invisible select markers * Fix linter issue * Fix crashing product details page * Fix e2e error * Update snapshots * Allow view taxes with any staff permissions (#2510) * Update after rebase Co-authored-by: Dawid <tarasiukdawid@gmail.com>
2022-11-17 12:48:50 +00:00
mergeData?: boolean;
2019-06-19 14:40:52 +00:00
}
Exit dirty form (#1816) * Add Exit form prompt component and change some minor styles in other components to match * Add Exit form prompt provider * Adjust generic form and useform hook to allow using exit form prompt provider * Add exit form prompt provider to index * wip * Fix types * Fix styling * Fix types * Revert warehouse details refactor * Add handling of edge cases to exit prompt * Refactor, add comments, fix some types * Refactor after exit form dialog name change * fix types * Fixes after review * Add default value for useform prop opts so the app doesn't crash * Add missing category prop to getting initial data for category details form * Add exit dialog to everywhere WIP (#1600) * Add Exit form prompt component and change some minor styles in other components to match * Add Exit form prompt provider * Adjust generic form and useform hook to allow using exit form prompt provider * Add exit form prompt provider to index * wip * Fix types * Fix styling * Fix types * Revert warehouse details refactor * Add handling of edge cases to exit prompt * Refactor, add comments, fix some types * Refactor after exit form dialog name change * fix types * Add CommonUseFormResultWithHandlers type for later use and refactor handleFormSubmit util * Refactor login form not to use custom form since it doesn't need to * Add exit form dialog to order refund page * Add exit form dialog to order return page * Add exit form dialog to order order settings page * Add exit form dialog to product variant page * Add exit form dialog to product create page * Add exit form dialog to product update page * Add exit form dialog to product variant create page * Fix confirm leave prop passing in generic Form * Add util function to handle for submit to extract errors * Add confirmLeave prop to generic forms * Move handleChange for custom forms to useForm * Add exit dialog to more forms * Add extract mutation errors util function * Add extracting errors to submit functions that use metadata create handler * Fix typo * Add missing category prop to getting initial data for category details form * Fix types * wip * wip * wip * wip * Fix types & refactor * Fix types & refactor * Fix typescript * Fix unmatching tag * Fixes * Add handling of multiple forms at once to exit dirty form provider * Change all usages of ExitFormDialogContext to designated hook * wip * wip * wip * Fix types wip * Fix types * Remove console logs * Add isSubmitting prop to exit form dialog in order to avoid enabling exit dialog while submit is still in progresS * Replace handleSubmit global util with a hook to use exit form dialog props inside * Move useHandleSubmit to general hooks dir, update imports * Small fixes * Update snapshots * Fix types * Small fixes due to extensive rebase * Update package lock * Fixes after rebase * Remove exit form from customer address dialog * Fix types and update messages * Fix types * Change imports names * Refactor * Remove unnecessary console.log * Update types, snapshots. etc after rebase
2022-02-01 09:58:06 +00:00
function Form<TData, Terrors>({
children,
initial,
resetOnSubmit,
onSubmit,
confirmLeave = false,
formId,
checkIfSaveIsDisabled,
disabled,
🦄 Simple taxes (#2072) * Tax configuration - implement channels view (#2048) * Add channels view * Fix channels view import * Remove legacy stories references * Fix link in configuration * Update snapshots * Remove sample checkboxes props * Disable hover in country exceptions * Update snapshots * Extract country exception rows to seperate component * Extract components to seperate files * Remove duplicated section name * Remove backlink * Add translations to section names * Extract messages * Add ListItemLink component * Replace navigator with link in TaxChannelsMenu * Fix horizontal scroll in TaxChannelsMenu * Change codegen to build from custom schema * Build types * Update fragments * Add fixtures * Change any to proper types * Add story for tax channels page * Replace MUI Skeleton with Saleor Skeleton * Change clsx import to classnames * Fix checkboxes shadows in settings card * Update IDs in fixtures * Fix offset in TaxChannelsMenu * Update snapshots * Remove any from TaxSettings * Fix todos * Change relative marginLeft to before pseudoelement * Extract styles to seperate files * Change folder structure * Extract redirect logic to custom hook * Update snapshots * Fix comment * Add early return in channels view * Tax configuration - implement countries view (#2053) * Add channels view * Remove sample checkboxes props * Disable hover in country exceptions * Extract country exception rows to seperate component * Extract components to seperate files * Remove duplicated section name * Remove backlink * Add translations to section names * Replace navigator with link in TaxChannelsMenu * Fix horizontal scroll in TaxChannelsMenu * Change any to proper types * Add story for tax channels page * Replace MUI Skeleton with Saleor Skeleton * Change clsx import to classnames * Fix checkboxes shadows in settings card * Update IDs in fixtures * Fix offset in TaxChannelsMenu * Remove any from TaxSettings * Add countries list view * Add TaxCountryMenu component * Add CountryList page * Change channels menu rows height * Change countries menu rows height * Add TaxInput component * Add tax classes rates to countries page * Fix search input padding * Add minmax to TaxInput * Add searching through tax class rates * Extract messages * Add better handlers * Add fullWidth to TaxInput * Specify type for TaxInputs * Remove spinboxes on firefox * Remove custom spinboxes * Remove maxHeight from menu rows * Post-rebase fix * Change setter to formchagne * Add TaxConfiguration fragment * Add isDefault field to taxClass * Add fixtures * Shape data * Replace useEffect with useTaxUrlRedirect * Fix country names in menu * Add country page story * Add early return in countries view * Unify loading states between channels and countries pages * Handle special chars and case insensitiveness in local search * Replace navigate function with ListItemLink * Move styles to seperate file * Move styles to seperate file * Migrate to strict null checks * Remove unnecessary optional chaining * Change overflow scroll to Y only * Add useMemo on finding selected country * Add useMemo on local search * Translate labels in page tabs * Change url from /taxes/classes to /taxes/tax-classes * Remove capitalization from strings * Extract messages * Bump macaw to 0.6.2 * Update snapshots * Add spinboxes explanation comment * Handle empty state * Add tax classes view (#2093) * Add TaxClass fragment * Build types * Add tax classes to fixtures * Add tax classes view * wip Add tax classes page * Add tax classes menu * Add TaxRate fragment * Extract logic * Handle loading state & add story * Extract messages * Update snapshots * Change schema building from schema back to introspection * Update schema * Update fragments * Build types * Update fixtures * Reshape data * Move styles to seperate file * Use getById * Add explicit undefined * Comment out unfinished modal stories * Update snapshots * Taxes - add API calls in channels view (#2106) * Build types * Add TaxRate fragment * Update snapshots * Add taxConfigurationList query * Add taxCountriesList query * Add TaxClassesList query * Rename TaxConfigurationsList query * Handle empty state * Fix types post-rebase * Add form to TaxChannelsPage * wip Add dialog for handling country exceptions * wip Fix dialog url * wip Add update exceptions handlers * Add dialog story * Fix type errors * Add mutation support * Fix types in story * Add transition state to submit button * Add notifier * Extract messages * Remove unused import * Add backlink in savebar * Update snapshots * Fix link in navigation * Update snapshots * Remove message from tax config error fragment * Add hook description * Use useStateFromProps * Remove error handling * Improve url & path function names * Use theme.spacing in TaxCountryDialog styles * Remove redundant key modification * Revert "Use useStateFromProps" This reverts commit d3c68b04701cf935e917d7baa3ed1361ca3446d5. * Move initial map to parent & add open dependency to countries state * Use useModalDialogOpen * Fix state update * Remove scrolls & add ellipsis in side menu * Center checkboxes * Update snapshots * Add fake div for list alignment * Trigger deployment * Close modal on submit * Remove divider on last ListItem * Align add country button * Wrap grid child in div to avoid card stretching * Update snapshots * Trigger changes in add/delete exceptions * Trigger change on expcetion checkboxes * Add trailing commas * Connect countries view to API (#2178) * Add empty states * Update countries view urls * Remove unused import * Add country modal to countries view * Update schema * Implement country view mutations & error fragments * Implement tax class update mutation * Add sidebar temporary state for new configs * Remove unused imports * Wrap in form * Add savebar & fix search * Update schema * Add form wrapper * Fix types * Extract messages * Bump macaw * Update snapshots * Fix comma dangles * Update snapshots * Notify about mutation success * Add logic for mixing current and new rates * Workaround for sending null rates * Fix filling form with correct data after submitting * Handle deleting configuration * Fix selected banner * Remove leftover comment * Add handler for country configuration delete * Trigger deployment * Clean up useEffects causing infinite render loops * Sort countries from api by name * Fix card bottom padding * Remove bottom divider & fix padding * Remove scroll wrapper in side menu * Update snapshots * Remove scroll wrapper from tax classes menu * Update snapshots * Refresh form to initial onSubmit * Revert "Refresh form to initial onSubmit" This reverts commit 42414237d35086da63f4aa088c8072411429b1d8. * Allow only 3 decimal characters in tax inputs * Update snapshots * Update schema * Update types * Change logic from default tax class to null class * Fix sorting * Send empty country rates as nulls in mutation * Extract messages * Update lockfile * Update schema * Drop default tax classes * Update snapshots * Post-rebase fixes * Connect tax classes view to API (#2334) * Add mutations * Handle empty state * Wrap page in form * Update stories * Build types * Handle tax class delete * Handle update tax class * Update stories * Handle tax class change name * Add mutation state to savebar * Handle creating new tax classes * Extract messages * Specify type * Update stories * Sort rates * Fix skeleton rendering * Remove placeholders * Fix skeleton rendering on country list * Update snapshots * Change initial pagination to 100 * Disallow creating multiple new tax classes * Disallow creating multiple country configurations * Fix messages * Autofocus on new tax class name * Add country name to header * Temporarily comment out broken code in tax channels * Update snapshots * Update snapshots post-rebase * Add tax strategies & assigning tax classes (#2369) * Update fragments * Add optional merging in useForm * Handle tax strategies * Update snapshots * Update fixtures * Extract messages * Remove unused shop query fields * Fix breaking bug when fetchMore is used in non-searchable SingleAutocompleteSelectFields * Migrate product types to tax classes * Add tax classes to shipping methods * Use encapsulated logic in product types * Fix product type stories * Fix shipping fixtures * Fix product type type mismatch * Fix shipping stories * Fix product type fixtures * Fix mismatching types * Extract messages * Update snapshots * Update snapshots * Fix comment * Drop deprecated graphql fields * Replace tax types with tax classes in product create view * Replace tax types with tax classes in product update view * Fix tests, stories, fixtures * Extract messages * Update snapshots * Move status messages to commonStatusMessages * Handle empty array case in tax class change handler * Reuse messages * Simple taxes bugfixes (#2395) * Fix tax channels menu - dense layout * Change view names to fit convention * Fix per country exceptions in tax channels view * Fix skeleton rendering on tax countries card title * Filter out existing countries from modal * Update snapshots * Fix deleting country configuration * Disallow negative values in tax inputs * Handle empty tax classes view * Allow empty options in shipping & product types views tax class assignment field * Modify undefined rates in tax classes view * Update macaw-ui * Fix UI on channels view * Fix UI on countries view * Fix UI on countries view * Align tax class rate label to the right * Updaste snapshots * Extract messages * Fix adding rates on new tax class * Fix key errors * Update schema * Build types * Allow empty rates in taxClassUpdate mutation * Extract tax channels change country function as a handler * Deprecate useStateFromProps * Change useStateFromProps to useStateUpdate * Fix dividers * Delete delete icon on new tax classes * Update snapshots * Update lockfile * Update macaw to 0.6.6 * Update snapshots * Specify type of input in country change handler * Extract autofocus logic to custom hook * Replace alternative with switch statement * Extract country exclusion logic from JSX * Update lockfile * Update lockfile * Trigger deployment * Fix invisible select markers * Fix linter issue * Fix crashing product details page * Fix e2e error * Update snapshots * Allow view taxes with any staff permissions (#2510) * Update after rebase Co-authored-by: Dawid <tarasiukdawid@gmail.com>
2022-11-17 12:48:50 +00:00
mergeData,
Exit dirty form (#1816) * Add Exit form prompt component and change some minor styles in other components to match * Add Exit form prompt provider * Adjust generic form and useform hook to allow using exit form prompt provider * Add exit form prompt provider to index * wip * Fix types * Fix styling * Fix types * Revert warehouse details refactor * Add handling of edge cases to exit prompt * Refactor, add comments, fix some types * Refactor after exit form dialog name change * fix types * Fixes after review * Add default value for useform prop opts so the app doesn't crash * Add missing category prop to getting initial data for category details form * Add exit dialog to everywhere WIP (#1600) * Add Exit form prompt component and change some minor styles in other components to match * Add Exit form prompt provider * Adjust generic form and useform hook to allow using exit form prompt provider * Add exit form prompt provider to index * wip * Fix types * Fix styling * Fix types * Revert warehouse details refactor * Add handling of edge cases to exit prompt * Refactor, add comments, fix some types * Refactor after exit form dialog name change * fix types * Add CommonUseFormResultWithHandlers type for later use and refactor handleFormSubmit util * Refactor login form not to use custom form since it doesn't need to * Add exit form dialog to order refund page * Add exit form dialog to order return page * Add exit form dialog to order order settings page * Add exit form dialog to product variant page * Add exit form dialog to product create page * Add exit form dialog to product update page * Add exit form dialog to product variant create page * Fix confirm leave prop passing in generic Form * Add util function to handle for submit to extract errors * Add confirmLeave prop to generic forms * Move handleChange for custom forms to useForm * Add exit dialog to more forms * Add extract mutation errors util function * Add extracting errors to submit functions that use metadata create handler * Fix typo * Add missing category prop to getting initial data for category details form * Fix types * wip * wip * wip * wip * Fix types & refactor * Fix types & refactor * Fix typescript * Fix unmatching tag * Fixes * Add handling of multiple forms at once to exit dirty form provider * Change all usages of ExitFormDialogContext to designated hook * wip * wip * wip * Fix types wip * Fix types * Remove console logs * Add isSubmitting prop to exit form dialog in order to avoid enabling exit dialog while submit is still in progresS * Replace handleSubmit global util with a hook to use exit form dialog props inside * Move useHandleSubmit to general hooks dir, update imports * Small fixes * Update snapshots * Fix types * Small fixes due to extensive rebase * Update package lock * Fixes after rebase * Remove exit form from customer address dialog * Fix types and update messages * Fix types * Change imports names * Refactor * Remove unnecessary console.log * Update types, snapshots. etc after rebase
2022-02-01 09:58:06 +00:00
...rest
}: FormProps<TData, Terrors>) {
const renderProps = useForm(initial, onSubmit, {
confirmLeave,
formId,
checkIfSaveIsDisabled,
disabled,
🦄 Simple taxes (#2072) * Tax configuration - implement channels view (#2048) * Add channels view * Fix channels view import * Remove legacy stories references * Fix link in configuration * Update snapshots * Remove sample checkboxes props * Disable hover in country exceptions * Update snapshots * Extract country exception rows to seperate component * Extract components to seperate files * Remove duplicated section name * Remove backlink * Add translations to section names * Extract messages * Add ListItemLink component * Replace navigator with link in TaxChannelsMenu * Fix horizontal scroll in TaxChannelsMenu * Change codegen to build from custom schema * Build types * Update fragments * Add fixtures * Change any to proper types * Add story for tax channels page * Replace MUI Skeleton with Saleor Skeleton * Change clsx import to classnames * Fix checkboxes shadows in settings card * Update IDs in fixtures * Fix offset in TaxChannelsMenu * Update snapshots * Remove any from TaxSettings * Fix todos * Change relative marginLeft to before pseudoelement * Extract styles to seperate files * Change folder structure * Extract redirect logic to custom hook * Update snapshots * Fix comment * Add early return in channels view * Tax configuration - implement countries view (#2053) * Add channels view * Remove sample checkboxes props * Disable hover in country exceptions * Extract country exception rows to seperate component * Extract components to seperate files * Remove duplicated section name * Remove backlink * Add translations to section names * Replace navigator with link in TaxChannelsMenu * Fix horizontal scroll in TaxChannelsMenu * Change any to proper types * Add story for tax channels page * Replace MUI Skeleton with Saleor Skeleton * Change clsx import to classnames * Fix checkboxes shadows in settings card * Update IDs in fixtures * Fix offset in TaxChannelsMenu * Remove any from TaxSettings * Add countries list view * Add TaxCountryMenu component * Add CountryList page * Change channels menu rows height * Change countries menu rows height * Add TaxInput component * Add tax classes rates to countries page * Fix search input padding * Add minmax to TaxInput * Add searching through tax class rates * Extract messages * Add better handlers * Add fullWidth to TaxInput * Specify type for TaxInputs * Remove spinboxes on firefox * Remove custom spinboxes * Remove maxHeight from menu rows * Post-rebase fix * Change setter to formchagne * Add TaxConfiguration fragment * Add isDefault field to taxClass * Add fixtures * Shape data * Replace useEffect with useTaxUrlRedirect * Fix country names in menu * Add country page story * Add early return in countries view * Unify loading states between channels and countries pages * Handle special chars and case insensitiveness in local search * Replace navigate function with ListItemLink * Move styles to seperate file * Move styles to seperate file * Migrate to strict null checks * Remove unnecessary optional chaining * Change overflow scroll to Y only * Add useMemo on finding selected country * Add useMemo on local search * Translate labels in page tabs * Change url from /taxes/classes to /taxes/tax-classes * Remove capitalization from strings * Extract messages * Bump macaw to 0.6.2 * Update snapshots * Add spinboxes explanation comment * Handle empty state * Add tax classes view (#2093) * Add TaxClass fragment * Build types * Add tax classes to fixtures * Add tax classes view * wip Add tax classes page * Add tax classes menu * Add TaxRate fragment * Extract logic * Handle loading state & add story * Extract messages * Update snapshots * Change schema building from schema back to introspection * Update schema * Update fragments * Build types * Update fixtures * Reshape data * Move styles to seperate file * Use getById * Add explicit undefined * Comment out unfinished modal stories * Update snapshots * Taxes - add API calls in channels view (#2106) * Build types * Add TaxRate fragment * Update snapshots * Add taxConfigurationList query * Add taxCountriesList query * Add TaxClassesList query * Rename TaxConfigurationsList query * Handle empty state * Fix types post-rebase * Add form to TaxChannelsPage * wip Add dialog for handling country exceptions * wip Fix dialog url * wip Add update exceptions handlers * Add dialog story * Fix type errors * Add mutation support * Fix types in story * Add transition state to submit button * Add notifier * Extract messages * Remove unused import * Add backlink in savebar * Update snapshots * Fix link in navigation * Update snapshots * Remove message from tax config error fragment * Add hook description * Use useStateFromProps * Remove error handling * Improve url & path function names * Use theme.spacing in TaxCountryDialog styles * Remove redundant key modification * Revert "Use useStateFromProps" This reverts commit d3c68b04701cf935e917d7baa3ed1361ca3446d5. * Move initial map to parent & add open dependency to countries state * Use useModalDialogOpen * Fix state update * Remove scrolls & add ellipsis in side menu * Center checkboxes * Update snapshots * Add fake div for list alignment * Trigger deployment * Close modal on submit * Remove divider on last ListItem * Align add country button * Wrap grid child in div to avoid card stretching * Update snapshots * Trigger changes in add/delete exceptions * Trigger change on expcetion checkboxes * Add trailing commas * Connect countries view to API (#2178) * Add empty states * Update countries view urls * Remove unused import * Add country modal to countries view * Update schema * Implement country view mutations & error fragments * Implement tax class update mutation * Add sidebar temporary state for new configs * Remove unused imports * Wrap in form * Add savebar & fix search * Update schema * Add form wrapper * Fix types * Extract messages * Bump macaw * Update snapshots * Fix comma dangles * Update snapshots * Notify about mutation success * Add logic for mixing current and new rates * Workaround for sending null rates * Fix filling form with correct data after submitting * Handle deleting configuration * Fix selected banner * Remove leftover comment * Add handler for country configuration delete * Trigger deployment * Clean up useEffects causing infinite render loops * Sort countries from api by name * Fix card bottom padding * Remove bottom divider & fix padding * Remove scroll wrapper in side menu * Update snapshots * Remove scroll wrapper from tax classes menu * Update snapshots * Refresh form to initial onSubmit * Revert "Refresh form to initial onSubmit" This reverts commit 42414237d35086da63f4aa088c8072411429b1d8. * Allow only 3 decimal characters in tax inputs * Update snapshots * Update schema * Update types * Change logic from default tax class to null class * Fix sorting * Send empty country rates as nulls in mutation * Extract messages * Update lockfile * Update schema * Drop default tax classes * Update snapshots * Post-rebase fixes * Connect tax classes view to API (#2334) * Add mutations * Handle empty state * Wrap page in form * Update stories * Build types * Handle tax class delete * Handle update tax class * Update stories * Handle tax class change name * Add mutation state to savebar * Handle creating new tax classes * Extract messages * Specify type * Update stories * Sort rates * Fix skeleton rendering * Remove placeholders * Fix skeleton rendering on country list * Update snapshots * Change initial pagination to 100 * Disallow creating multiple new tax classes * Disallow creating multiple country configurations * Fix messages * Autofocus on new tax class name * Add country name to header * Temporarily comment out broken code in tax channels * Update snapshots * Update snapshots post-rebase * Add tax strategies & assigning tax classes (#2369) * Update fragments * Add optional merging in useForm * Handle tax strategies * Update snapshots * Update fixtures * Extract messages * Remove unused shop query fields * Fix breaking bug when fetchMore is used in non-searchable SingleAutocompleteSelectFields * Migrate product types to tax classes * Add tax classes to shipping methods * Use encapsulated logic in product types * Fix product type stories * Fix shipping fixtures * Fix product type type mismatch * Fix shipping stories * Fix product type fixtures * Fix mismatching types * Extract messages * Update snapshots * Update snapshots * Fix comment * Drop deprecated graphql fields * Replace tax types with tax classes in product create view * Replace tax types with tax classes in product update view * Fix tests, stories, fixtures * Extract messages * Update snapshots * Move status messages to commonStatusMessages * Handle empty array case in tax class change handler * Reuse messages * Simple taxes bugfixes (#2395) * Fix tax channels menu - dense layout * Change view names to fit convention * Fix per country exceptions in tax channels view * Fix skeleton rendering on tax countries card title * Filter out existing countries from modal * Update snapshots * Fix deleting country configuration * Disallow negative values in tax inputs * Handle empty tax classes view * Allow empty options in shipping & product types views tax class assignment field * Modify undefined rates in tax classes view * Update macaw-ui * Fix UI on channels view * Fix UI on countries view * Fix UI on countries view * Align tax class rate label to the right * Updaste snapshots * Extract messages * Fix adding rates on new tax class * Fix key errors * Update schema * Build types * Allow empty rates in taxClassUpdate mutation * Extract tax channels change country function as a handler * Deprecate useStateFromProps * Change useStateFromProps to useStateUpdate * Fix dividers * Delete delete icon on new tax classes * Update snapshots * Update lockfile * Update macaw to 0.6.6 * Update snapshots * Specify type of input in country change handler * Extract autofocus logic to custom hook * Replace alternative with switch statement * Extract country exclusion logic from JSX * Update lockfile * Update lockfile * Trigger deployment * Fix invisible select markers * Fix linter issue * Fix crashing product details page * Fix e2e error * Update snapshots * Allow view taxes with any staff permissions (#2510) * Update after rebase Co-authored-by: Dawid <tarasiukdawid@gmail.com>
2022-11-17 12:48:50 +00:00
mergeData,
});
2019-06-19 14:40:52 +00:00
2019-08-09 11:14:35 +00:00
function handleSubmit(event?: React.FormEvent<any>, cb?: () => void) {
const { reset, submit } = renderProps;
2019-06-19 14:40:52 +00:00
if (event) {
event.stopPropagation();
event.preventDefault();
}
2019-08-09 11:14:35 +00:00
2019-06-19 14:40:52 +00:00
if (cb) {
cb();
}
2019-08-09 11:14:35 +00:00
2019-06-19 14:40:52 +00:00
if (resetOnSubmit) {
2019-08-09 11:14:35 +00:00
reset();
2019-06-19 14:40:52 +00:00
}
2019-08-09 11:14:35 +00:00
submit();
2019-06-19 14:40:52 +00:00
}
2019-08-09 11:14:35 +00:00
2021-11-23 09:03:07 +00:00
return (
<form {...rest} onSubmit={handleSubmit}>
{children(renderProps)}
</form>
);
2019-06-19 14:40:52 +00:00
}
2019-08-09 11:14:35 +00:00
Form.displayName = "Form";
export default Form;