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; +export type FormType = Pick; 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 = () => { 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; deleteService: (service: Service) => Promise; createService: (service: ServiceCreate) => Promise; - editService: (service: Service) => Promise; + editService: (service: ServiceCreate) => Promise; fetchUserUsage: (user: User, query: FilterUsageType) => Promise; 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 +export type ServiceCreate = { + id: number | undefined; + name: string; + inbounds: number[]; +}