mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-14 21:10:34 +01:00
clean-up edit forms, removed unused params
This commit is contained in:
parent
3277b65993
commit
74ea4f511e
@ -8,19 +8,13 @@ import {
|
||||
TextField,
|
||||
SubmitButton,
|
||||
PasswordField,
|
||||
useToasts,
|
||||
} from 'react-basics';
|
||||
import { useApi, useMessages } from 'components/hooks';
|
||||
import { ROLES } from 'lib/constants';
|
||||
import { useRef } from 'react';
|
||||
|
||||
export function UserEditForm({
|
||||
userId,
|
||||
data,
|
||||
onSave,
|
||||
}: {
|
||||
userId: string;
|
||||
data: object;
|
||||
onSave?: (data: any) => void;
|
||||
}) {
|
||||
export function UserEditForm({ userId, data }: { userId: string; data: object }) {
|
||||
const { formatMessage, labels, messages } = useMessages();
|
||||
const { post, useMutation } = useApi();
|
||||
const { mutate, error } = useMutation({
|
||||
@ -34,11 +28,14 @@ export function UserEditForm({
|
||||
role: string;
|
||||
}) => post(`/users/${userId}`, { username, password, role }),
|
||||
});
|
||||
const ref = useRef(null);
|
||||
const { showToast } = useToasts();
|
||||
|
||||
const handleSubmit = async (data: any) => {
|
||||
mutate(data, {
|
||||
onSuccess: async () => {
|
||||
onSave(data);
|
||||
showToast({ message: formatMessage(messages.saved), variant: 'success' });
|
||||
ref.current.reset(data);
|
||||
},
|
||||
});
|
||||
};
|
||||
@ -56,7 +53,7 @@ export function UserEditForm({
|
||||
};
|
||||
|
||||
return (
|
||||
<Form onSubmit={handleSubmit} error={error} values={data} style={{ width: 300 }}>
|
||||
<Form ref={ref} onSubmit={handleSubmit} error={error} values={data} style={{ width: 300 }}>
|
||||
<FormRow label={formatMessage(labels.username)}>
|
||||
<FormInput name="username">
|
||||
<TextField />
|
||||
|
@ -13,12 +13,7 @@ import { DOMAIN_REGEX } from 'lib/constants';
|
||||
import { touch } from 'store/modified';
|
||||
import { WebsiteContext } from 'app/(main)/websites/[websiteId]/WebsiteProvider';
|
||||
|
||||
export function WebsiteEditForm({
|
||||
websiteId,
|
||||
}: {
|
||||
websiteId: string;
|
||||
onSave?: (data: any) => void;
|
||||
}) {
|
||||
export function WebsiteEditForm({ websiteId }: { websiteId: string }) {
|
||||
const website = useContext(WebsiteContext);
|
||||
const { formatMessage, labels, messages } = useMessages();
|
||||
const { post, useMutation } = useApi();
|
||||
|
@ -47,7 +47,7 @@ export default async (
|
||||
include: {
|
||||
_count: {
|
||||
select: {
|
||||
website: {
|
||||
websiteUser: {
|
||||
where: { deletedAt: null },
|
||||
},
|
||||
},
|
||||
|
@ -21,7 +21,7 @@ async function findUser(
|
||||
...criteria,
|
||||
where: {
|
||||
...criteria.where,
|
||||
...(showDeleted && { delatedAt: null }),
|
||||
...(showDeleted && { deletedAt: null }),
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
|
Loading…
x
Reference in New Issue
Block a user