Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

clean-up edit forms, removed unused params

Francis Cao74ea4f511eea
diff --git a/src/app/(main)/settings/users/UserEditForm.tsx b/src/app/(main)/settings/users/UserEditForm.tsx
index 12c5afbcb..d904be47b 100644
--- a/src/app/(main)/settings/users/UserEditForm.tsx
+++ b/src/app/(main)/settings/users/UserEditForm.tsx
@@ -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 />
diff --git a/src/app/(main)/settings/websites/[websiteId]/WebsiteEditForm.tsx b/src/app/(main)/settings/websites/[websiteId]/WebsiteEditForm.tsx
index 53f27b26e..543261ddc 100644
--- a/src/app/(main)/settings/websites/[websiteId]/WebsiteEditForm.tsx
+++ b/src/app/(main)/settings/websites/[websiteId]/WebsiteEditForm.tsx
@@ -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();
diff --git a/src/pages/api/admin/users.ts b/src/pages/api/admin/users.ts
index 0eecb447d..31b72ebf9 100644
--- a/src/pages/api/admin/users.ts
+++ b/src/pages/api/admin/users.ts
@@ -47,7 +47,7 @@ export default async (
include: {
_count: {
select: {
- website: {
+ websiteUser: {
where: { deletedAt: null },
},
},
diff --git a/src/queries/admin/user.ts b/src/queries/admin/user.ts
index a9a90c5a2..0b5fe349e 100644
--- a/src/queries/admin/user.ts
+++ b/src/queries/admin/user.ts
@@ -21,7 +21,7 @@ async function findUser(
...criteria,
where: {
...criteria.where,
- ...(showDeleted && { delatedAt: null }),
+ ...(showDeleted && { deletedAt: null }),
},
select: {
id: true,