2023-01-06 06:56:36 +00:00
|
|
|
import {
|
|
|
|
|
Form,
|
|
|
|
|
FormRow,
|
|
|
|
|
FormInput,
|
|
|
|
|
FormButtons,
|
|
|
|
|
TextField,
|
|
|
|
|
Button,
|
|
|
|
|
SubmitButton,
|
|
|
|
|
} from 'react-basics';
|
2024-01-29 02:33:40 +00:00
|
|
|
import { useApi } from 'components/hooks';
|
2022-12-27 00:57:59 +00:00
|
|
|
import { DOMAIN_REGEX } from 'lib/constants';
|
2024-01-29 02:33:40 +00:00
|
|
|
import { useMessages } from 'components/hooks';
|
2022-12-27 00:57:59 +00:00
|
|
|
|
2024-01-29 02:33:40 +00:00
|
|
|
export function WebsiteAddForm({
|
|
|
|
|
teamId,
|
|
|
|
|
onSave,
|
|
|
|
|
onClose,
|
|
|
|
|
}: {
|
|
|
|
|
teamId: string;
|
|
|
|
|
onSave?: () => void;
|
|
|
|
|
onClose?: () => void;
|
|
|
|
|
}) {
|
2023-03-23 18:46:49 +00:00
|
|
|
const { formatMessage, labels, messages } = useMessages();
|
2023-01-10 07:59:26 +00:00
|
|
|
const { post, useMutation } = useApi();
|
2023-12-03 11:07:03 +00:00
|
|
|
const { mutate, error, isPending } = useMutation({
|
2024-01-29 11:15:22 +00:00
|
|
|
mutationFn: (data: any) => post('/websites', { ...data, teamId }),
|
2023-12-03 11:07:03 +00:00
|
|
|
});
|
2022-12-27 00:57:59 +00:00
|
|
|
|
2023-11-13 22:12:05 +00:00
|
|
|
const handleSubmit = async (data: any) => {
|
2022-12-27 00:57:59 +00:00
|
|
|
mutate(data, {
|
|
|
|
|
onSuccess: async () => {
|
2023-11-13 22:12:05 +00:00
|
|
|
onSave?.();
|
|
|
|
|
onClose?.();
|
2022-12-27 00:57:59 +00:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
2023-12-03 11:07:03 +00:00
|
|
|
<Form onSubmit={handleSubmit} error={error}>
|
2023-01-25 15:42:46 +00:00
|
|
|
<FormRow label={formatMessage(labels.name)}>
|
2023-01-23 23:32:35 +00:00
|
|
|
<FormInput name="name" rules={{ required: formatMessage(labels.required) }}>
|
2023-01-06 06:56:36 +00:00
|
|
|
<TextField autoComplete="off" />
|
|
|
|
|
</FormInput>
|
|
|
|
|
</FormRow>
|
2023-01-25 15:42:46 +00:00
|
|
|
<FormRow label={formatMessage(labels.domain)}>
|
2023-01-06 06:56:36 +00:00
|
|
|
<FormInput
|
|
|
|
|
name="domain"
|
|
|
|
|
rules={{
|
2023-01-23 23:32:35 +00:00
|
|
|
required: formatMessage(labels.required),
|
2023-03-23 18:46:49 +00:00
|
|
|
pattern: { value: DOMAIN_REGEX, message: formatMessage(messages.invalidDomain) },
|
2023-01-06 06:56:36 +00:00
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<TextField autoComplete="off" />
|
|
|
|
|
</FormInput>
|
|
|
|
|
</FormRow>
|
2022-12-27 00:57:59 +00:00
|
|
|
<FormButtons flex>
|
|
|
|
|
<SubmitButton variant="primary" disabled={false}>
|
2023-01-23 23:32:35 +00:00
|
|
|
{formatMessage(labels.save)}
|
2022-12-27 00:57:59 +00:00
|
|
|
</SubmitButton>
|
2023-11-13 22:12:05 +00:00
|
|
|
{onClose && (
|
2023-12-03 11:07:03 +00:00
|
|
|
<Button disabled={isPending} onClick={onClose}>
|
2023-11-13 22:12:05 +00:00
|
|
|
{formatMessage(labels.cancel)}
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
2022-12-27 00:57:59 +00:00
|
|
|
</FormButtons>
|
|
|
|
|
</Form>
|
|
|
|
|
);
|
|
|
|
|
}
|
2023-04-21 15:00:42 +00:00
|
|
|
|
|
|
|
|
export default WebsiteAddForm;
|