Refactored settings components.

This commit is contained in:
Mike Cao 2023-01-09 23:59:26 -08:00
parent d827b79c72
commit 7450b76e6d
91 changed files with 736 additions and 353 deletions

View file

@ -0,0 +1,39 @@
import { Form, FormRow, FormButtons, FormInput, TextField, SubmitButton } from 'react-basics';
import { useRef } from 'react';
import useApi from 'hooks/useApi';
export default function AccountEditForm({ data, onSave }) {
const { id } = data;
const { post, useMutation } = useApi();
const { mutate, error } = useMutation(({ name }) => post(`/accounts/${id}`, { name }));
const ref = useRef(null);
const handleSubmit = async data => {
mutate(data, {
onSuccess: async () => {
onSave(data);
ref.current.reset(data);
},
});
};
return (
<>
<Form key={id} ref={ref} onSubmit={handleSubmit} error={error} values={data}>
<FormRow label="Name">
<FormInput name="name">
<TextField autoComplete="off" />
</FormInput>
</FormRow>
<FormRow label="Email">
<FormInput name="email">
<TextField readOnly />
</FormInput>
</FormRow>
<FormButtons>
<SubmitButton variant="primary">Save</SubmitButton>
</FormButtons>
</Form>
</>
);
}