2022-11-17 17:19:44 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import deprecated from '@wordpress/deprecated';
|
2023-02-13 11:43:57 +00:00
|
|
|
import { FieldValidationStatus } from '@woocommerce/types';
|
2022-11-17 17:19:44 +00:00
|
|
|
|
2022-07-01 23:06:25 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { ACTION_TYPES as types } from './action-types';
|
|
|
|
import { ReturnOrGeneratorYieldUnion } from '../mapped-types';
|
|
|
|
|
|
|
|
export const setValidationErrors = (
|
|
|
|
errors: Record< string, FieldValidationStatus >
|
|
|
|
) => ( {
|
|
|
|
type: types.SET_VALIDATION_ERRORS,
|
|
|
|
errors,
|
|
|
|
} );
|
|
|
|
|
2022-11-17 17:19:44 +00:00
|
|
|
/**
|
|
|
|
* Clears validation errors for the given ids.
|
|
|
|
*
|
2023-12-12 23:05:20 +00:00
|
|
|
* @param errors Array of error ids to clear.
|
2022-11-17 17:19:44 +00:00
|
|
|
*/
|
|
|
|
export const clearValidationErrors = ( errors?: string[] | undefined ) => ( {
|
|
|
|
type: types.CLEAR_VALIDATION_ERRORS,
|
|
|
|
errors,
|
2022-07-01 23:06:25 +00:00
|
|
|
} );
|
|
|
|
|
2022-11-17 17:19:44 +00:00
|
|
|
export const clearAllValidationErrors = () => {
|
|
|
|
deprecated( 'clearAllValidationErrors', {
|
|
|
|
version: '9.0.0',
|
|
|
|
alternative: 'clearValidationErrors',
|
|
|
|
plugin: 'WooCommerce Blocks',
|
|
|
|
link: 'https://github.com/woocommerce/woocommerce-blocks/pull/7601',
|
|
|
|
hint: 'Calling `clearValidationErrors` with no arguments will clear all validation errors.',
|
|
|
|
} );
|
|
|
|
|
|
|
|
// Return clearValidationErrors which will clear all errors by defaults if no error ids are passed.
|
|
|
|
return clearValidationErrors();
|
|
|
|
};
|
|
|
|
|
2022-07-01 23:06:25 +00:00
|
|
|
export const clearValidationError = ( error: string ) => ( {
|
|
|
|
type: types.CLEAR_VALIDATION_ERROR,
|
|
|
|
error,
|
|
|
|
} );
|
2022-10-05 10:04:16 +00:00
|
|
|
|
2022-07-01 23:06:25 +00:00
|
|
|
export const hideValidationError = ( error: string ) => ( {
|
|
|
|
type: types.HIDE_VALIDATION_ERROR,
|
|
|
|
error,
|
|
|
|
} );
|
2022-10-05 10:04:16 +00:00
|
|
|
|
2022-07-01 23:06:25 +00:00
|
|
|
export const showValidationError = ( error: string ) => ( {
|
|
|
|
type: types.SHOW_VALIDATION_ERROR,
|
|
|
|
error,
|
|
|
|
} );
|
2022-10-05 10:04:16 +00:00
|
|
|
|
2022-07-01 23:06:25 +00:00
|
|
|
export const showAllValidationErrors = () => ( {
|
|
|
|
type: types.SHOW_ALL_VALIDATION_ERRORS,
|
|
|
|
} );
|
2022-10-05 10:04:16 +00:00
|
|
|
|
2022-07-01 23:06:25 +00:00
|
|
|
export type ValidationAction = ReturnOrGeneratorYieldUnion<
|
|
|
|
| typeof setValidationErrors
|
|
|
|
| typeof clearAllValidationErrors
|
|
|
|
| typeof clearValidationError
|
2022-11-17 17:19:44 +00:00
|
|
|
| typeof clearValidationErrors
|
2022-07-01 23:06:25 +00:00
|
|
|
| typeof hideValidationError
|
|
|
|
| typeof showValidationError
|
|
|
|
| typeof showAllValidationErrors
|
|
|
|
>;
|