gitscope
← marzneshin / Diff · 123de7e → 123de7e
Changes 123de7e..123de7e
Patch commit
diff --git a/app/dashboard/src/components/Dialog/index.tsx b/app/dashboard/src/components/Dialog/index.tsx
deleted file mode 100644
index e69de29..0000000
diff --git a/app/dashboard/src/components/ServiceDialog/FormSchema.ts b/app/dashboard/src/components/ServiceDialog/FormSchema.ts
index 5d41b3a..36f96e4 100644
--- a/app/dashboard/src/components/ServiceDialog/FormSchema.ts
+++ b/app/dashboard/src/components/ServiceDialog/FormSchema.ts
@@ -2,7 +2,7 @@
import { z } from 'zod';
import { ServiceCreate } from 'types/Service';
-export type FormType = Pick<ServiceCreate, keyof ServiceCreate>;
+export type FormType = Pick<ServiceCreate, 'name' | 'inbounds'>;
export const schema = z.object({
name: z.string().min(1, { message: 'Name is required' }),
inbounds: z.array(z.number()).nonempty({ message: 'At least one inbounds is required' }),
diff --git a/app/dashboard/src/components/ServiceDialog/index.tsx b/app/dashboard/src/components/ServiceDialog/index.tsx
index 557cc5b..c11b72c 100644
--- a/app/dashboard/src/components/ServiceDialog/index.tsx
+++ b/app/dashboard/src/components/ServiceDialog/index.tsx
@@ -87,9 +87,7 @@ export const ServiceDialog: FC<ServiceDialogProps> = () => {
setError(null);
const { inbounds, name } = values;
- let body: Service | ServiceCreate = (isEditing) ?
- { name, inbounds, id: editingService.id }
- : { name, inbounds };
+ let body: ServiceCreate = { name, inbounds, id: editingService?.id };
await methods[method](body)
.then(() => {
diff --git a/app/dashboard/src/contexts/DashboardContext.tsx b/app/dashboard/src/contexts/DashboardContext.tsx
index 7d4df4f..37d82c0 100644
--- a/app/dashboard/src/contexts/DashboardContext.tsx
+++ b/app/dashboard/src/contexts/DashboardContext.tsx
@@ -88,7 +88,7 @@ type DashboardStateType = {
editUser: (user: UserCreate) => Promise<void>;
deleteService: (service: Service) => Promise<void>;
createService: (service: ServiceCreate) => Promise<void>;
- editService: (service: Service) => Promise<void>;
+ editService: (service: ServiceCreate) => Promise<void>;
fetchUserUsage: (user: User, query: FilterUsageType) => Promise<void>;
setQRCode: (links: string[] | null) => void;
setSubLink: (subscribeURL: string | null) => void;
@@ -263,7 +263,7 @@ export const useDashboard = create(
queryClient.invalidateQueries(StatisticsQueryKey);
});
},
- editService: async (body: Service) => {
+ editService: async (body: ServiceCreate) => {
return fetch(`/service/${body.id}`, { method: 'PUT', body }).then(
() => {
get().onEditingUser(null);
diff --git a/app/dashboard/src/types/Service.ts b/app/dashboard/src/types/Service.ts
index 263d355..4331754 100644
--- a/app/dashboard/src/types/Service.ts
+++ b/app/dashboard/src/types/Service.ts
@@ -6,6 +6,8 @@ export type Service = {
inbounds: number[];
}
-export type ServiceCreate = Pick<Service,
- | 'name'
- | 'inbounds'>
+export type ServiceCreate = {
+ id: number | undefined;
+ name: string;
+ inbounds: number[];
+}