♻️ refactor: Replace useQuery with Zustand store for subscription and node data management
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import { getSubscribeList } from '@/services/admin/subscribe';
|
||||
import { useSubscribe } from '@/store/subscribe';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { Button } from '@workspace/ui/components/button';
|
||||
import {
|
||||
Form,
|
||||
@@ -81,16 +80,7 @@ export default function CouponForm<T extends Record<string, any>>({
|
||||
|
||||
const type = form.watch('type');
|
||||
|
||||
const { data: subscribe } = useQuery({
|
||||
queryKey: ['getSubscribeList', 'all'],
|
||||
queryFn: async () => {
|
||||
const { data } = await getSubscribeList({
|
||||
page: 1,
|
||||
size: 9999,
|
||||
});
|
||||
return data.data?.list as API.Subscribe[];
|
||||
},
|
||||
});
|
||||
const { subscribes } = useSubscribe();
|
||||
|
||||
return (
|
||||
<Sheet open={open} onOpenChange={setOpen}>
|
||||
@@ -247,9 +237,9 @@ export default function CouponForm<T extends Record<string, any>>({
|
||||
onChange={(value) => {
|
||||
form.setValue(field.name, value);
|
||||
}}
|
||||
options={subscribe?.map((item: API.Subscribe) => ({
|
||||
value: item.id,
|
||||
label: item.name,
|
||||
options={subscribes?.map((item) => ({
|
||||
value: item.id!,
|
||||
label: item.name!,
|
||||
}))}
|
||||
/>
|
||||
</FormControl>
|
||||
|
||||
@@ -9,9 +9,8 @@ import {
|
||||
getCouponList,
|
||||
updateCoupon,
|
||||
} from '@/services/admin/coupon';
|
||||
import { getSubscribeList } from '@/services/admin/subscribe';
|
||||
import { useSubscribe } from '@/store/subscribe';
|
||||
import { formatDate } from '@/utils/common';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { Badge } from '@workspace/ui/components/badge';
|
||||
import { Button } from '@workspace/ui/components/button';
|
||||
import { Switch } from '@workspace/ui/components/switch';
|
||||
@@ -24,16 +23,7 @@ import CouponForm from './coupon-form';
|
||||
export default function Page() {
|
||||
const t = useTranslations('coupon');
|
||||
const [loading, setLoading] = useState(false);
|
||||
const { data } = useQuery({
|
||||
queryKey: ['getSubscribeList', 'all'],
|
||||
queryFn: async () => {
|
||||
const { data } = await getSubscribeList({
|
||||
page: 1,
|
||||
size: 9999,
|
||||
});
|
||||
return data.data?.list as API.SubscribeGroup[];
|
||||
},
|
||||
});
|
||||
const { subscribes } = useSubscribe();
|
||||
const ref = useRef<ProTableActions>(null);
|
||||
return (
|
||||
<ProTable<API.Coupon, { group_id: number; query: string }>
|
||||
@@ -67,8 +57,8 @@ export default function Page() {
|
||||
{
|
||||
key: 'subscribe',
|
||||
placeholder: t('subscribe'),
|
||||
options: data?.map((item) => ({
|
||||
label: item.name,
|
||||
options: subscribes?.map((item) => ({
|
||||
label: item.name!,
|
||||
value: String(item.id),
|
||||
})),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user