2022-12-27 01:57:59 +01:00
|
|
|
import { useRef } from 'react';
|
2023-01-06 07:56:36 +01:00
|
|
|
import {
|
|
|
|
Form,
|
|
|
|
FormRow,
|
|
|
|
FormInput,
|
|
|
|
FormButtons,
|
|
|
|
TextField,
|
|
|
|
Button,
|
|
|
|
SubmitButton,
|
|
|
|
} from 'react-basics';
|
2022-12-28 05:20:44 +01:00
|
|
|
import useApi from 'hooks/useApi';
|
2022-12-27 01:57:59 +01:00
|
|
|
import { DOMAIN_REGEX } from 'lib/constants';
|
|
|
|
|
|
|
|
export default function WebsiteAddForm({ onSave, onClose }) {
|
2023-01-10 08:59:26 +01:00
|
|
|
const { post, useMutation } = useApi();
|
2022-12-27 01:57:59 +01:00
|
|
|
const { mutate, error, isLoading } = useMutation(data => post('/websites', data));
|
|
|
|
const ref = useRef(null);
|
|
|
|
|
|
|
|
const handleSubmit = async data => {
|
|
|
|
mutate(data, {
|
|
|
|
onSuccess: async () => {
|
|
|
|
onSave();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2023-01-10 08:59:26 +01:00
|
|
|
<Form ref={ref} onSubmit={handleSubmit} error={error}>
|
2023-01-06 07:56:36 +01:00
|
|
|
<FormRow label="Name">
|
|
|
|
<FormInput name="name" rules={{ required: 'Required' }}>
|
|
|
|
<TextField autoComplete="off" />
|
|
|
|
</FormInput>
|
|
|
|
</FormRow>
|
|
|
|
<FormRow label="Domain">
|
|
|
|
<FormInput
|
|
|
|
name="domain"
|
|
|
|
rules={{
|
|
|
|
required: 'Required',
|
|
|
|
pattern: { value: DOMAIN_REGEX, message: 'Invalid domain' },
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<TextField autoComplete="off" />
|
|
|
|
</FormInput>
|
|
|
|
</FormRow>
|
2022-12-27 01:57:59 +01:00
|
|
|
<FormButtons flex>
|
|
|
|
<SubmitButton variant="primary" disabled={false}>
|
|
|
|
Save
|
|
|
|
</SubmitButton>
|
|
|
|
<Button disabled={isLoading} onClick={onClose}>
|
|
|
|
Cancel
|
|
|
|
</Button>
|
|
|
|
</FormButtons>
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
}
|