fix(striker-ui): remove disableAutocomplete from formik utils

main
Tsu-ba-me 11 months ago
parent bd65517449
commit ddece3750d
  1. 123
      striker-ui/components/ManageMailServer/AddMailServerForm.tsx
  2. 13
      striker-ui/hooks/useFormikUtils.ts
  3. 5
      striker-ui/types/FormikUtils.d.ts

@ -26,78 +26,73 @@ const AddMailServerForm: FC<AddMailServerFormProps> = (props) => {
[mailServerUuid],
);
const {
disableAutocomplete,
disabledSubmit,
formik,
formikErrors,
handleChange,
} = useFormikUtils<MailServerFormikValues>({
initialValues: previousFormikValues ?? {
[msUuid]: {
address: '',
authentication: 'none',
heloDomain: localhostDomain,
port: 587,
security: 'none',
uuid: msUuid,
const { disabledSubmit, formik, formikErrors, handleChange } =
useFormikUtils<MailServerFormikValues>({
initialValues: previousFormikValues ?? {
[msUuid]: {
address: '',
authentication: 'none',
heloDomain: localhostDomain,
port: 587,
security: 'none',
uuid: msUuid,
},
},
},
onSubmit: (values, { setSubmitting }) => {
const { [msUuid]: mailServer } = values;
onSubmit: (values, { setSubmitting }) => {
const { [msUuid]: mailServer } = values;
let actionProceedText: string = 'Add';
let errorMessage: ReactNode = <>Failed to add mail server.</>;
let method: 'post' | 'put' = 'post';
let successMessage = <>Mail server added.</>;
let titleText: string = 'Add mail server with the following?';
let url = '/mail-server';
let actionProceedText: string = 'Add';
let errorMessage: ReactNode = <>Failed to add mail server.</>;
let method: 'post' | 'put' = 'post';
let successMessage = <>Mail server added.</>;
let titleText: string = 'Add mail server with the following?';
let url = '/mail-server';
if (previousFormikValues) {
actionProceedText = 'Update';
errorMessage = <>Failed to update mail server.</>;
method = 'put';
successMessage = <>Mail server updated.</>;
titleText = `Update ${mailServer.address}:${mailServer.port} with the following?`;
url += `/${msUuid}`;
}
if (previousFormikValues) {
actionProceedText = 'Update';
errorMessage = <>Failed to update mail server.</>;
method = 'put';
successMessage = <>Mail server updated.</>;
titleText = `Update ${mailServer.address}:${mailServer.port} with the following?`;
url += `/${msUuid}`;
}
const { confirmPassword, uuid, ...rest } = mailServer;
const { confirmPassword, uuid, ...rest } = mailServer;
tools.confirm.prepare({
actionProceedText,
content: <FormSummary entries={rest} />,
onCancelAppend: () => setSubmitting(false),
onProceedAppend: () => {
tools.confirm.loading(true);
tools.confirm.prepare({
actionProceedText,
content: <FormSummary entries={rest} />,
onCancelAppend: () => setSubmitting(false),
onProceedAppend: () => {
tools.confirm.loading(true);
api[method](url, mailServer)
.then(() => {
tools.confirm.finish('Success', { children: successMessage });
api[method](url, mailServer)
.then(() => {
tools.confirm.finish('Success', { children: successMessage });
tools[method === 'post' ? 'add' : 'edit'].open(false);
})
.catch((error) => {
const emsg = handleAPIError(error);
tools[method === 'post' ? 'add' : 'edit'].open(false);
})
.catch((error) => {
const emsg = handleAPIError(error);
emsg.children = (
<>
{errorMessage} {emsg.children}
</>
);
emsg.children = (
<>
{errorMessage} {emsg.children}
</>
);
tools.confirm.finish('Error', emsg);
tools.confirm.finish('Error', emsg);
setSubmitting(false);
});
},
titleText,
});
setSubmitting(false);
});
},
titleText,
});
tools.confirm.open(true);
},
validationSchema: mailServerListSchema,
});
tools.confirm.open(true);
},
validationSchema: mailServerListSchema,
});
const addressChain = useMemo<string>(() => `${msUuid}.address`, [msUuid]);
const authenticationChain = useMemo<string>(
@ -206,8 +201,8 @@ const AddMailServerForm: FC<AddMailServerFormProps> = (props) => {
<UncontrolledInput
input={
<OutlinedInputWithLabel
disableAutofill
id={usernameChain}
inputProps={disableAutocomplete()}
label="Server username"
name={usernameChain}
onChange={handleChange}
@ -220,8 +215,8 @@ const AddMailServerForm: FC<AddMailServerFormProps> = (props) => {
<UncontrolledInput
input={
<OutlinedInputWithLabel
disableAutofill
id={passwordChain}
inputProps={disableAutocomplete()}
label="Server password"
name={passwordChain}
onChange={handleChange}
@ -236,8 +231,8 @@ const AddMailServerForm: FC<AddMailServerFormProps> = (props) => {
<UncontrolledInput
input={
<OutlinedInputWithLabel
disableAutofill
id={confirmPasswordChain}
inputProps={disableAutocomplete()}
label="Confirm password"
name={confirmPasswordChain}
onChange={handleChange}

@ -1,4 +1,3 @@
import { OutlinedInputProps } from '@mui/material';
import { FormikConfig, FormikValues, useFormik } from 'formik';
import { isEqual, isObject } from 'lodash';
import { useCallback, useMemo } from 'react';
@ -41,17 +40,6 @@ const useFormikUtils = <Values extends FormikValues = FormikValues>(
[formik.initialValues, formik.values],
);
const disableAutocomplete = useCallback(
(overwrite?: Partial<OutlinedInputProps>): OutlinedInputProps => ({
readOnly: true,
onFocus: (event) => {
event.target.readOnly = false;
},
...overwrite,
}),
[],
);
const debounceHandleChange = useMemo(
() => debounce(formik.handleChange),
[formik.handleChange],
@ -75,7 +63,6 @@ const useFormikUtils = <Values extends FormikValues = FormikValues>(
);
return {
disableAutocomplete,
disabledSubmit,
formik,
formikErrors,

@ -12,11 +12,6 @@ type FormikSubmitHandler<Values extends FormikValues> =
import('formik').FormikConfig<Values>['onSubmit'];
type FormikUtils<Values extends FormikValues> = {
disableAutocomplete: (
overwrite?: Partial<
import('../components/OutlinedInput').OutlinedInputProps
>,
) => import('../components/OutlinedInput').OutlinedInputProps;
disabledSubmit: boolean;
formik: Formik<Values>;
formikErrors: Messages;

Loading…
Cancel
Save