Browse Source

✨ feat(coupon): 移除创建/编辑领券日志功能

- 删除创建/编辑对话框相关代码
- 移除创建和编辑表单组件及相关逻辑

🐛 fix(coupon): 修复删除接口状态码判断错误

- 将删除成功状态码判断从200改为204

💄 style(coupon): 简化toast提示调用方式

- 使用toast.success()和toast.error()简化成功和错误提示
- 移除冗余的toast配置参数
yourname 6 months ago
parent
commit
a72537dad4
1 changed files with 5 additions and 203 deletions
  1. 5 203
      src/client/admin-shadcn/pages/CouponLogs.tsx

+ 5 - 203
src/client/admin-shadcn/pages/CouponLogs.tsx

@@ -153,16 +153,12 @@ export default function CouponLogs() {
       return response.json();
     },
     onSuccess: () => {
-      toast({ title: '更新成功' });
+      toast.success('更新成功');
       setIsModalOpen(false);
       refetch();
     },
     onError: (error) => {
-      toast({ 
-        title: '更新失败', 
-        description: error.message,
-        variant: 'destructive' 
-      });
+      toast.error('更新失败');
     }
   });
 
@@ -172,21 +168,17 @@ export default function CouponLogs() {
       const response = await couponLogClient[':id']['$delete']({
         param: { id: id.toString() }
       });
-      if (response.status !== 200) {
+      if (response.status !== 204) {
         throw new Error('删除失败');
       }
       return response.json();
     },
     onSuccess: () => {
-      toast({ title: '删除成功' });
+      toast.success('删除成功');
       refetch();
     },
     onError: (error) => {
-      toast({ 
-        title: '删除失败', 
-        description: error.message,
-        variant: 'destructive' 
-      });
+      toast.error('删除失败');
     }
   });
 
@@ -393,196 +385,6 @@ export default function CouponLogs() {
           </div>
         </CardContent>
       </Card>
-
-      {/* 创建/编辑对话框 */}
-      <Dialog open={isModalOpen} onOpenChange={setIsModalOpen}>
-        <DialogContent className="sm:max-w-[600px]">
-          <DialogHeader>
-            <DialogTitle>{isCreateForm ? '创建领券日志' : '编辑领券日志'}</DialogTitle>
-            <DialogDescription>
-              {isCreateForm ? '创建新的领券日志记录' : '编辑现有的领券日志信息'}
-            </DialogDescription>
-          </DialogHeader>
-
-          <Form {...(isCreateForm ? createForm : updateForm)}>
-            <form 
-              onSubmit={(isCreateForm ? createForm : updateForm).handleSubmit(
-                isCreateForm ? handleCreateSubmit : handleUpdateSubmit
-              )} 
-              className="space-y-4"
-            >
-              <FormField
-                control={(isCreateForm ? createForm : updateForm).control}
-                name="couponId"
-                render={({ field }) => (
-                  <FormItem>
-                    <FormLabel className="flex items-center">
-                      券ID
-                      <span className="text-red-500 ml-1">*</span>
-                    </FormLabel>
-                    <FormControl>
-                      <Input placeholder="请输入券ID" {...field} />
-                    </FormControl>
-                    <FormMessage />
-                  </FormItem>
-                )}
-              />
-
-              <FormField
-                control={(isCreateForm ? createForm : updateForm).control}
-                name="batchId"
-                render={({ field }) => (
-                  <FormItem>
-                    <FormLabel className="flex items-center">
-                      批次号
-                      <span className="text-red-500 ml-1">*</span>
-                    </FormLabel>
-                    <FormControl>
-                      <Input placeholder="请输入批次号" {...field} />
-                    </FormControl>
-                    <FormMessage />
-                  </FormItem>
-                )}
-              />
-
-              <div className="grid grid-cols-2 gap-4">
-                <FormField
-                  control={(isCreateForm ? createForm : updateForm).control}
-                  name="batchCategoryId"
-                  render={({ field }) => (
-                    <FormItem>
-                      <FormLabel className="flex items-center">
-                        批次分类ID
-                        <span className="text-red-500 ml-1">*</span>
-                      </FormLabel>
-                      <FormControl>
-                        <Input 
-                          type="number" 
-                          placeholder="请输入批次分类ID" 
-                          {...field}
-                          onChange={(e) => field.onChange(parseInt(e.target.value))}
-                        />
-                      </FormControl>
-                      <FormMessage />
-                    </FormItem>
-                  )}
-                />
-
-                <FormField
-                  control={(isCreateForm ? createForm : updateForm).control}
-                  name="exchangeCodeId"
-                  render={({ field }) => (
-                    <FormItem>
-                      <FormLabel className="flex items-center">
-                        兑换码ID
-                        <span className="text-red-500 ml-1">*</span>
-                      </FormLabel>
-                      <FormControl>
-                        <Input 
-                          type="number" 
-                          placeholder="请输入兑换码ID" 
-                          {...field}
-                          onChange={(e) => field.onChange(parseInt(e.target.value))}
-                        />
-                      </FormControl>
-                      <FormMessage />
-                    </FormItem>
-                  )}
-                />
-              </div>
-
-              <FormField
-                control={(isCreateForm ? createForm : updateForm).control}
-                name="userId"
-                render={({ field }) => (
-                  <FormItem>
-                    <FormLabel className="flex items-center">
-                      用户ID
-                      <span className="text-red-500 ml-1">*</span>
-                    </FormLabel>
-                    <FormControl>
-                      <Input 
-                        type="number" 
-                        placeholder="请输入用户ID" 
-                        {...field}
-                        onChange={(e) => field.onChange(parseInt(e.target.value))}
-                      />
-                    </FormControl>
-                    <FormMessage />
-                  </FormItem>
-                )}
-              />
-
-              <FormField
-                control={(isCreateForm ? createForm : updateForm).control}
-                name="result"
-                render={({ field }) => (
-                  <FormItem className="flex flex-row items-center justify-between rounded-lg border p-4">
-                    <div className="space-y-0.5">
-                      <FormLabel className="text-base">领取结果</FormLabel>
-                      <FormDescription>
-                        设置领取结果为成功或失败
-                      </FormDescription>
-                    </div>
-                    <FormControl>
-                      <Select
-                        value={field.value.toString()}
-                        onValueChange={(value) => field.onChange(parseInt(value))}
-                      >
-                        <SelectTrigger className="w-[180px]">
-                          <SelectValue />
-                        </SelectTrigger>
-                        <SelectContent>
-                          <SelectItem value="0">失败</SelectItem>
-                          <SelectItem value="1">成功</SelectItem>
-                        </SelectContent>
-                      </Select>
-                    </FormControl>
-                  </FormItem>
-                )}
-              />
-
-              <FormField
-                control={(isCreateForm ? createForm : updateForm).control}
-                name="failReason"
-                render={({ field }) => (
-                  <FormItem>
-                    <FormLabel>失败原因</FormLabel>
-                    <FormControl>
-                      <Input 
-                        placeholder="请输入失败原因(可选)" 
-                        {...field}
-                        value={field.value || ''}
-                      />
-                    </FormControl>
-                    <FormMessage />
-                  </FormItem>
-                )}
-              />
-
-              <DialogFooter>
-                <Button 
-                  type="button" 
-                  variant="outline" 
-                  onClick={() => setIsModalOpen(false)}
-                >
-                  取消
-                </Button>
-                <Button 
-                  type="submit" 
-                  disabled={
-                    isCreateForm 
-                      ? createMutation.isPending 
-                      : updateMutation.isPending
-                  }
-                >
-                  {isCreateForm ? '创建' : '更新'}
-                </Button>
-              </DialogFooter>
-            </form>
-          </Form>
-        </DialogContent>
-      </Dialog>
     </div>
   );
 }