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';
|
2023-03-22 22:05:55 +01:00
|
|
|
import useMessages from 'hooks/useMessages';
|
2022-12-27 01:57:59 +01:00
|
|
|
|
2023-04-21 17:00:42 +02:00
|
|
|
export function WebsiteAddForm({ onSave, onClose }) {
|
2023-03-23 19:46:49 +01:00
|
|
|
const { formatMessage, labels, messages } = useMessages();
|
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 handleSubmit = async data => {
|
|
|
|
mutate(data, {
|
|
|
|
onSuccess: async () => {
|
|
|
|
onSave();
|
2023-01-28 06:53:13 +01:00
|
|
|
onClose();
|
2022-12-27 01:57:59 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2023-01-24 00:32:35 +01:00
|
|
|
<Form onSubmit={handleSubmit} error={error}>
|
2023-01-25 16:42:46 +01:00
|
|
|
<FormRow label={formatMessage(labels.name)}>
|
2023-01-24 00:32:35 +01:00
|
|
|
<FormInput name="name" rules={{ required: formatMessage(labels.required) }}>
|
2023-01-06 07:56:36 +01:00
|
|
|
<TextField autoComplete="off" />
|
|
|
|
</FormInput>
|
|
|
|
</FormRow>
|
2023-01-25 16:42:46 +01:00
|
|
|
<FormRow label={formatMessage(labels.domain)}>
|
2023-01-06 07:56:36 +01:00
|
|
|
<FormInput
|
|
|
|
name="domain"
|
|
|
|
rules={{
|
2023-01-24 00:32:35 +01:00
|
|
|
required: formatMessage(labels.required),
|
2023-03-23 19:46:49 +01:00
|
|
|
pattern: { value: DOMAIN_REGEX, message: formatMessage(messages.invalidDomain) },
|
2023-01-06 07:56:36 +01:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
<TextField autoComplete="off" />
|
|
|
|
</FormInput>
|
|
|
|
</FormRow>
|
2022-12-27 01:57:59 +01:00
|
|
|
<FormButtons flex>
|
|
|
|
<SubmitButton variant="primary" disabled={false}>
|
2023-01-24 00:32:35 +01:00
|
|
|
{formatMessage(labels.save)}
|
2022-12-27 01:57:59 +01:00
|
|
|
</SubmitButton>
|
|
|
|
<Button disabled={isLoading} onClick={onClose}>
|
2023-01-24 00:32:35 +01:00
|
|
|
{formatMessage(labels.cancel)}
|
2022-12-27 01:57:59 +01:00
|
|
|
</Button>
|
|
|
|
</FormButtons>
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
}
|
2023-04-21 17:00:42 +02:00
|
|
|
|
|
|
|
export default WebsiteAddForm;
|