fix(striker-ui): migrate setApiMessage from manifest manager

main
Tsu-ba-me 1 year ago
parent 28f36c6d85
commit ece7efda99
  1. 13
      striker-ui/components/ManageManifest/ManageManifestPanel.tsx
  2. 7
      striker-ui/hooks/useFormUtils.ts
  3. 11
      striker-ui/types/FormUtils.d.ts

@ -47,8 +47,6 @@ import useFormUtils from '../../hooks/useFormUtils';
import useIsFirstRender from '../../hooks/useIsFirstRender';
import useProtectedState from '../../hooks/useProtectedState';
const MSG_ID_MANIFEST_API = 'api';
const getFormData = (
...[{ target }]: DivFormEventHandlerParameters
): APIBuildManifestRequestBody => {
@ -190,7 +188,7 @@ const ManageManifestPanel: FC = () => {
],
messageGroupRef,
);
const { isFormInvalid, setMessage } = formUtils;
const { isFormInvalid, setApiMessage } = formUtils;
const runFormUtils = useFormUtils(
[
@ -245,22 +243,19 @@ const ManageManifestPanel: FC = () => {
api
.request({ data: body, method, url })
.then(() => {
setMessage(MSG_ID_MANIFEST_API, {
children: successMsg,
type: 'info',
});
setApiMessage({ children: successMsg, type: 'info' });
})
.catch((apiError) => {
const emsg = handleAPIError(apiError);
emsg.children = getErrorMsg(emsg.children);
setMessage(MSG_ID_MANIFEST_API, emsg);
setApiMessage(emsg);
})
.finally(() => {
setIsSubmittingForm(false);
});
},
[setIsSubmittingForm, setMessage],
[setApiMessage, setIsSubmittingForm],
);
const addManifestFormDialogProps = useMemo<ConfirmDialogProps>(

@ -20,6 +20,12 @@ const useFormUtils = <
const [formSubmitting, setFormSubmitting] = useProtectedState<boolean>(false);
const [formValidity, setFormValidity] = useState<FormValidity<M>>({});
const setApiMessage = useCallback(
(message?: Message) =>
messageGroupRef?.current?.setMessage?.call(null, 'api', message),
[messageGroupRef],
);
const setMessage = useCallback(
(key: keyof M, message?: Message) => {
messageGroupRef?.current?.setMessage?.call(null, String(key), message);
@ -136,6 +142,7 @@ const useFormUtils = <
formValidity,
isFormInvalid: formInvalid,
isFormSubmitting: formSubmitting,
setApiMessage,
setFormValidity,
setMessage,
setMessageRe,

@ -41,17 +41,12 @@ type FormUtils<M extends MapToInputTestID> = {
formValidity: FormValidity<M>;
isFormInvalid: boolean;
isFormSubmitting: boolean;
setApiMessage: (message?: Message) => void;
setFormValidity: import('react').Dispatch<
import('react').SetStateAction<FormValidity<M>>
>;
setMessage: (
key: keyof M,
message?: import('../components/MessageBox').Message,
) => void;
setMessageRe: (
re: RegExp,
message?: import('../components/MessageBox').Message,
) => void;
setMessage: (key: keyof M, message?: Message) => void;
setMessageRe: (re: RegExp, message?: Message) => void;
setValidity: (key: keyof M, value?: boolean) => void;
setValidityRe: (re: RegExp, value?: boolean) => void;
submitForm: SubmitFormFunction;

Loading…
Cancel
Save