mirror of
https://github.com/umami-software/umami.git
synced 2026-02-18 19:45:35 +01:00
Updated website, team and user save.
This commit is contained in:
parent
2fa50892d8
commit
fec81695e8
15 changed files with 128 additions and 117 deletions
|
|
@ -1,40 +1,46 @@
|
|||
import { SubmitButton, Form, FormInput, FormRow, FormButtons, TextField } from 'react-basics';
|
||||
import { useContext, useRef } from 'react';
|
||||
import { useApi } from 'components/hooks';
|
||||
import { Website } from '@prisma/client';
|
||||
import { useRef } from 'react';
|
||||
import {
|
||||
SubmitButton,
|
||||
Form,
|
||||
FormInput,
|
||||
FormRow,
|
||||
FormButtons,
|
||||
TextField,
|
||||
useToasts,
|
||||
} from 'react-basics';
|
||||
import { useApi, useMessages } from 'components/hooks';
|
||||
import { DOMAIN_REGEX } from 'lib/constants';
|
||||
import { useMessages } from 'components/hooks';
|
||||
import SettingsContext from '../../SettingsContext';
|
||||
|
||||
export function WebsiteEditForm({
|
||||
websiteId,
|
||||
data,
|
||||
website,
|
||||
onSave,
|
||||
}: {
|
||||
websiteId: string;
|
||||
data: any[];
|
||||
website: Website;
|
||||
onSave?: (data: any) => void;
|
||||
}) {
|
||||
const { formatMessage, labels, messages } = useMessages();
|
||||
const { websitesUrl } = useContext(SettingsContext);
|
||||
const { post, useMutation } = useApi();
|
||||
const { mutate, error } = useMutation({
|
||||
mutationFn: (data: any) => post(`${websitesUrl}/${websiteId}`, data),
|
||||
mutationFn: (data: any) => post(`/websites/${website.id}`, data),
|
||||
});
|
||||
const ref = useRef(null);
|
||||
const { showToast } = useToasts();
|
||||
|
||||
const handleSubmit = async (data: any) => {
|
||||
mutate(data, {
|
||||
onSuccess: async () => {
|
||||
showToast({ message: formatMessage(messages.saved), variant: 'success' });
|
||||
ref.current.reset(data);
|
||||
onSave(data);
|
||||
onSave?.(data);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Form ref={ref} onSubmit={handleSubmit} error={error} values={data}>
|
||||
<Form ref={ref} onSubmit={handleSubmit} error={error} values={website}>
|
||||
<FormRow label={formatMessage(labels.websiteId)}>
|
||||
<TextField value={websiteId} readOnly allowCopy />
|
||||
<TextField value={website.id} readOnly allowCopy />
|
||||
</FormRow>
|
||||
<FormRow label={formatMessage(labels.name)}>
|
||||
<FormInput name="name" rules={{ required: formatMessage(labels.required) }}>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue