260322:1648 Correct Coresspondence / Doing RFA / Correct CI
This commit is contained in:
@@ -1,26 +1,19 @@
|
||||
"use client";
|
||||
'use client';
|
||||
|
||||
import { useForm } from "react-hook-form";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import * as z from "zod";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Form,
|
||||
FormControl,
|
||||
FormField,
|
||||
FormItem,
|
||||
FormLabel,
|
||||
FormMessage
|
||||
} from "@/components/ui/form";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { toast } from "sonner";
|
||||
import { documentNumberingService } from "@/lib/services/document-numbering.service";
|
||||
import { CancelNumberDto } from "@/types/dto/numbering.dto";
|
||||
import { useState } from "react";
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import * as z from 'zod';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { toast } from 'sonner';
|
||||
import { documentNumberingService } from '@/lib/services/document-numbering.service';
|
||||
import { CancelNumberDto } from '@/types/dto/numbering.dto';
|
||||
import { useState } from 'react';
|
||||
|
||||
const formSchema = z.object({
|
||||
documentNumber: z.string().min(3, "Document Number is required"),
|
||||
reason: z.string().min(5, "Reason must be at least 5 characters"),
|
||||
documentNumber: z.string().min(3, 'Document Number is required'),
|
||||
reason: z.string().min(5, 'Reason must be at least 5 characters'),
|
||||
});
|
||||
|
||||
type CancelNumberFormData = z.infer<typeof formSchema>;
|
||||
@@ -31,8 +24,8 @@ export function CancelNumberForm() {
|
||||
const form = useForm<CancelNumberFormData>({
|
||||
resolver: zodResolver(formSchema) as any, // eslint-disable-line @typescript-eslint/no-explicit-any -- zod 4 + @hookform/resolvers compat
|
||||
defaultValues: {
|
||||
documentNumber: "",
|
||||
reason: "",
|
||||
documentNumber: '',
|
||||
reason: '',
|
||||
},
|
||||
});
|
||||
|
||||
@@ -41,10 +34,10 @@ export function CancelNumberForm() {
|
||||
try {
|
||||
const dto: CancelNumberDto = values;
|
||||
await documentNumberingService.cancelNumber(dto);
|
||||
toast.success("Number cancelled successfully.");
|
||||
toast.success('Number cancelled successfully.');
|
||||
form.reset();
|
||||
} catch (error) {
|
||||
toast.error("Failed to cancel number. It may not exist or is already cancelled.");
|
||||
} catch (_error) {
|
||||
toast.error('Failed to cancel number. It may not exist or is already cancelled.');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -54,30 +47,40 @@ export function CancelNumberForm() {
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4 border p-4 rounded-md">
|
||||
<h3 className="text-lg font-medium">Cancel Number</h3>
|
||||
<p className="text-sm text-gray-500">Permanently cancel a number (e.g. if generated by mistake). It cannot be reused.</p>
|
||||
<p className="text-sm text-gray-500">
|
||||
Permanently cancel a number (e.g. if generated by mistake). It cannot be reused.
|
||||
</p>
|
||||
|
||||
<FormField control={form.control} name="documentNumber" render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Document Number</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="e.g. LCB3-COR-GGL-2025-0001" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)} />
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="documentNumber"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Document Number</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="e.g. LCB3-COR-GGL-2025-0001" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField control={form.control} name="reason" render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Reason</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Reason for cancellation..." {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)} />
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="reason"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>Reason</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="Reason for cancellation..." {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
|
||||
<Button type="submit" variant="destructive" disabled={loading}>
|
||||
{loading ? "Cancelling..." : "Cancel Number"}
|
||||
{loading ? 'Cancelling...' : 'Cancel Number'}
|
||||
</Button>
|
||||
</form>
|
||||
</Form>
|
||||
|
||||
Reference in New Issue
Block a user