clean-up edit forms, removed unused params

This commit is contained in:
Francis Cao 2024-02-06 12:25:21 -08:00
parent 3277b65993
commit 74ea4f511e
4 changed files with 11 additions and 19 deletions

View File

@ -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 />

View File

@ -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();

View File

@ -47,7 +47,7 @@ export default async (
include: {
_count: {
select: {
website: {
websiteUser: {
where: { deletedAt: null },
},
},

View File

@ -21,7 +21,7 @@ async function findUser(
...criteria,
where: {
...criteria.where,
...(showDeleted && { delatedAt: null }),
...(showDeleted && { deletedAt: null }),
},
select: {
id: true,