|
|
@@ -1,4 +1,4 @@
|
|
|
-import React, { useState } from 'react';
|
|
|
+import { useState } from 'react';
|
|
|
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
|
|
import { format } from 'date-fns';
|
|
|
import { zhCN } from 'date-fns/locale';
|
|
|
@@ -21,7 +21,7 @@ import { Switch } from '@/client/components/ui/switch';
|
|
|
import { Skeleton } from '@/client/components/ui/skeleton';
|
|
|
import { DataTablePagination } from '@/client/admin/components/DataTablePagination';
|
|
|
import { UserSelector } from '@/client/admin/components/UserSelector';
|
|
|
-import { CityCascadeSelector } from '@/client/admin/components/CityCascadeSelector';
|
|
|
+import { AreaSelect } from '@/client/admin/components/AreaSelect';
|
|
|
|
|
|
// 类型定义
|
|
|
type DeliveryAddressResponse = InferResponseType<typeof deliveryAddressClient.$get, 200>['data'][0];
|
|
|
@@ -49,7 +49,7 @@ export const DeliveryAddressesPage = () => {
|
|
|
const [addressToDelete, setAddressToDelete] = useState<number | null>(null);
|
|
|
|
|
|
// 表单实例
|
|
|
- const createForm = useForm<CreateRequest>({
|
|
|
+ const createForm = useForm({
|
|
|
resolver: zodResolver(createFormSchema),
|
|
|
defaultValues: {
|
|
|
userId: 0,
|
|
|
@@ -64,7 +64,7 @@ export const DeliveryAddressesPage = () => {
|
|
|
},
|
|
|
});
|
|
|
|
|
|
- const updateForm = useForm<UpdateRequest>({
|
|
|
+ const updateForm = useForm({
|
|
|
resolver: zodResolver(updateFormSchema),
|
|
|
});
|
|
|
|
|
|
@@ -107,7 +107,7 @@ export const DeliveryAddressesPage = () => {
|
|
|
const updateMutation = useMutation({
|
|
|
mutationFn: async ({ id, data }: { id: number; data: UpdateRequest }) => {
|
|
|
const res = await deliveryAddressClient[':id']['$put']({
|
|
|
- param: { id: id.toString() },
|
|
|
+ param: { id },
|
|
|
json: data,
|
|
|
});
|
|
|
if (res.status !== 200) throw new Error('更新失败');
|
|
|
@@ -127,7 +127,7 @@ export const DeliveryAddressesPage = () => {
|
|
|
const deleteMutation = useMutation({
|
|
|
mutationFn: async (id: number) => {
|
|
|
const res = await deliveryAddressClient[':id']['$delete']({
|
|
|
- param: { id: id.toString() },
|
|
|
+ param: { id },
|
|
|
});
|
|
|
if (res.status !== 204) throw new Error('删除失败');
|
|
|
},
|
|
|
@@ -456,7 +456,7 @@ export const DeliveryAddressesPage = () => {
|
|
|
|
|
|
<div className="space-y-2">
|
|
|
<FormLabel>四级地址选择<span className="text-red-500 ml-1">*</span></FormLabel>
|
|
|
- <CityCascadeSelector
|
|
|
+ <AreaSelect
|
|
|
provinceValue={createForm.watch('receiverProvince') || 0}
|
|
|
cityValue={createForm.watch('receiverCity') || 0}
|
|
|
districtValue={createForm.watch('receiverDistrict') || 0}
|
|
|
@@ -545,7 +545,7 @@ export const DeliveryAddressesPage = () => {
|
|
|
|
|
|
<div className="space-y-2">
|
|
|
<FormLabel>四级地址选择<span className="text-red-500 ml-1">*</span></FormLabel>
|
|
|
- <CityCascadeSelector
|
|
|
+ <AreaSelect
|
|
|
provinceValue={updateForm.watch('receiverProvince') || 0}
|
|
|
cityValue={updateForm.watch('receiverCity') || 0}
|
|
|
districtValue={updateForm.watch('receiverDistrict') || 0}
|