|
|
@@ -41,13 +41,13 @@ import { z } from 'zod';
|
|
|
import { useForm } from 'react-hook-form';
|
|
|
import { zodResolver } from '@hookform/resolvers/zod';
|
|
|
import { Plus, Edit, Trash2 } from 'lucide-react';
|
|
|
-import { client } from '@/client/api';
|
|
|
+import { membershipPlanClient } from '@/client/api';
|
|
|
import type { InferResponseType, InferRequestType } from 'hono/client';
|
|
|
import { toast } from 'sonner';
|
|
|
|
|
|
-type MembershipPlan = InferResponseType<typeof client.api.v1['membership-plans'].$get, 200>['data'][0];
|
|
|
-type CreateMembershipPlanRequest = InferRequestType<typeof client.api.v1['membership-plans'].$post>['json'];
|
|
|
-type UpdateMembershipPlanRequest = InferRequestType<typeof client.api.v1['membership-plans'][number]['$put']>['json'];
|
|
|
+type MembershipPlan = InferResponseType<typeof membershipPlanClient.$get, 200>['data'][0];
|
|
|
+type CreateMembershipPlanRequest = InferRequestType<typeof membershipPlanClient.$post>['json'];
|
|
|
+type UpdateMembershipPlanRequest = InferRequestType<typeof membershipPlanClient[':id']['$put']>['json'];
|
|
|
|
|
|
const formSchema = z.object({
|
|
|
name: z.string().min(1, '套餐名称不能为空'),
|
|
|
@@ -68,7 +68,7 @@ export default function MembershipPlans() {
|
|
|
const { data: plans, isLoading } = useQuery({
|
|
|
queryKey: ['membership-plans'],
|
|
|
queryFn: async () => {
|
|
|
- const response = await client.api.v1['membership-plans'].$get();
|
|
|
+ const response = await membershipPlanClient.$get();
|
|
|
if (!response.ok) throw new Error('获取套餐失败');
|
|
|
const data = await response.json();
|
|
|
return data.data;
|
|
|
@@ -77,7 +77,7 @@ export default function MembershipPlans() {
|
|
|
|
|
|
const createMutation = useMutation({
|
|
|
mutationFn: async (data: CreateMembershipPlanRequest) => {
|
|
|
- const response = await client.api.v1['membership-plans'].$post({ json: data });
|
|
|
+ const response = await membershipPlanClient.$post({ json: data });
|
|
|
if (!response.ok) throw new Error('创建套餐失败');
|
|
|
return response.json();
|
|
|
},
|
|
|
@@ -93,7 +93,10 @@ export default function MembershipPlans() {
|
|
|
|
|
|
const updateMutation = useMutation({
|
|
|
mutationFn: async ({ id, data }: { id: number; data: UpdateMembershipPlanRequest }) => {
|
|
|
- const response = await client.api.v1['membership-plans'][id].$put({ json: data });
|
|
|
+ const response = await membershipPlanClient[':id'].$put({
|
|
|
+ param: { id },
|
|
|
+ json: data
|
|
|
+ });
|
|
|
if (!response.ok) throw new Error('更新套餐失败');
|
|
|
return response.json();
|
|
|
},
|
|
|
@@ -109,7 +112,9 @@ export default function MembershipPlans() {
|
|
|
|
|
|
const deleteMutation = useMutation({
|
|
|
mutationFn: async (id: number) => {
|
|
|
- const response = await client.api.v1['membership-plans'][id].$delete();
|
|
|
+ const response = await membershipPlanClient[':id'].$delete({
|
|
|
+ param: { id }
|
|
|
+ });
|
|
|
if (!response.ok) throw new Error('删除套餐失败');
|
|
|
return response.json();
|
|
|
},
|