mirror of
https://github.com/kremalicious/umami.git
synced 2024-12-24 18:26:20 +01:00
53 lines
1.7 KiB
JavaScript
53 lines
1.7 KiB
JavaScript
import { SubmitButton, Form, FormInput, FormRow, FormButtons, TextField } from 'react-basics';
|
|
import { useRef } from 'react';
|
|
import { useIntl } from 'react-intl';
|
|
import useApi from 'hooks/useApi';
|
|
import { DOMAIN_REGEX } from 'lib/constants';
|
|
import { labels, messages } from 'components/messages';
|
|
|
|
export default function WebsiteEditForm({ websiteId, data, onSave }) {
|
|
const { formatMessage } = useIntl();
|
|
const { post, useMutation } = useApi();
|
|
const { mutate, error } = useMutation(data => post(`/websites/${websiteId}`, data));
|
|
const ref = useRef(null);
|
|
|
|
const handleSubmit = async data => {
|
|
mutate(data, {
|
|
onSuccess: async () => {
|
|
ref.current.reset(data);
|
|
onSave(data);
|
|
},
|
|
});
|
|
};
|
|
|
|
return (
|
|
<Form ref={ref} onSubmit={handleSubmit} error={error} values={data} style={{ width: 600 }}>
|
|
<FormRow label={formatMessage(labels.websiteId)}>
|
|
<TextField value={websiteId} readOnly allowCopy />
|
|
</FormRow>
|
|
<FormRow label={formatMessage(labels.name)}>
|
|
<FormInput name="name" rules={{ required: formatMessage(labels.required) }}>
|
|
<TextField />
|
|
</FormInput>
|
|
</FormRow>
|
|
<FormRow label={formatMessage(labels.domain)}>
|
|
<FormInput
|
|
name="domain"
|
|
rules={{
|
|
required: formatMessage(labels.required),
|
|
pattern: {
|
|
value: DOMAIN_REGEX,
|
|
message: formatMessage(messages.invalidDomain),
|
|
},
|
|
}}
|
|
>
|
|
<TextField />
|
|
</FormInput>
|
|
</FormRow>
|
|
<FormButtons>
|
|
<SubmitButton variant="primary">{formatMessage(labels.save)}</SubmitButton>
|
|
</FormButtons>
|
|
</Form>
|
|
);
|
|
}
|