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,
|
TextField,
|
||||||
SubmitButton,
|
SubmitButton,
|
||||||
PasswordField,
|
PasswordField,
|
||||||
|
useToasts,
|
||||||
} from 'react-basics';
|
} from 'react-basics';
|
||||||
import { useApi, useMessages } from 'components/hooks';
|
import { useApi, useMessages } from 'components/hooks';
|
||||||
import { ROLES } from 'lib/constants';
|
import { ROLES } from 'lib/constants';
|
||||||
|
import { useRef } from 'react';
|
||||||
|
|
||||||
export function UserEditForm({
|
export function UserEditForm({ userId, data }: { userId: string; data: object }) {
|
||||||
userId,
|
|
||||||
data,
|
|
||||||
onSave,
|
|
||||||
}: {
|
|
||||||
userId: string;
|
|
||||||
data: object;
|
|
||||||
onSave?: (data: any) => void;
|
|
||||||
}) {
|
|
||||||
const { formatMessage, labels, messages } = useMessages();
|
const { formatMessage, labels, messages } = useMessages();
|
||||||
const { post, useMutation } = useApi();
|
const { post, useMutation } = useApi();
|
||||||
const { mutate, error } = useMutation({
|
const { mutate, error } = useMutation({
|
||||||
@ -34,11 +28,14 @@ export function UserEditForm({
|
|||||||
role: string;
|
role: string;
|
||||||
}) => post(`/users/${userId}`, { username, password, role }),
|
}) => post(`/users/${userId}`, { username, password, role }),
|
||||||
});
|
});
|
||||||
|
const ref = useRef(null);
|
||||||
|
const { showToast } = useToasts();
|
||||||
|
|
||||||
const handleSubmit = async (data: any) => {
|
const handleSubmit = async (data: any) => {
|
||||||
mutate(data, {
|
mutate(data, {
|
||||||
onSuccess: async () => {
|
onSuccess: async () => {
|
||||||
onSave(data);
|
showToast({ message: formatMessage(messages.saved), variant: 'success' });
|
||||||
|
ref.current.reset(data);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -56,7 +53,7 @@ export function UserEditForm({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
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)}>
|
<FormRow label={formatMessage(labels.username)}>
|
||||||
<FormInput name="username">
|
<FormInput name="username">
|
||||||
<TextField />
|
<TextField />
|
||||||
|
@ -13,12 +13,7 @@ import { DOMAIN_REGEX } from 'lib/constants';
|
|||||||
import { touch } from 'store/modified';
|
import { touch } from 'store/modified';
|
||||||
import { WebsiteContext } from 'app/(main)/websites/[websiteId]/WebsiteProvider';
|
import { WebsiteContext } from 'app/(main)/websites/[websiteId]/WebsiteProvider';
|
||||||
|
|
||||||
export function WebsiteEditForm({
|
export function WebsiteEditForm({ websiteId }: { websiteId: string }) {
|
||||||
websiteId,
|
|
||||||
}: {
|
|
||||||
websiteId: string;
|
|
||||||
onSave?: (data: any) => void;
|
|
||||||
}) {
|
|
||||||
const website = useContext(WebsiteContext);
|
const website = useContext(WebsiteContext);
|
||||||
const { formatMessage, labels, messages } = useMessages();
|
const { formatMessage, labels, messages } = useMessages();
|
||||||
const { post, useMutation } = useApi();
|
const { post, useMutation } = useApi();
|
||||||
|
@ -47,7 +47,7 @@ export default async (
|
|||||||
include: {
|
include: {
|
||||||
_count: {
|
_count: {
|
||||||
select: {
|
select: {
|
||||||
website: {
|
websiteUser: {
|
||||||
where: { deletedAt: null },
|
where: { deletedAt: null },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -21,7 +21,7 @@ async function findUser(
|
|||||||
...criteria,
|
...criteria,
|
||||||
where: {
|
where: {
|
||||||
...criteria.where,
|
...criteria.where,
|
||||||
...(showDeleted && { delatedAt: null }),
|
...(showDeleted && { deletedAt: null }),
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user