1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
import { vendorCandidates } from "@/db/schema/vendors"
import {
createSearchParamsCache,
parseAsArrayOf,
parseAsInteger,
parseAsString,
parseAsStringEnum,
} from "nuqs/server"
import * as z from "zod"
import { getFiltersStateParser, getSortingStateParser } from "@/lib/parsers"
export const searchParamsCandidateCache = createSearchParamsCache({
// Common flags
flags: parseAsArrayOf(z.enum(["advancedTable", "floatingBar"])).withDefault([]),
// Paging
page: parseAsInteger.withDefault(1),
perPage: parseAsInteger.withDefault(10),
// Sorting - adjusting for vendorInvestigationsView
sort: getSortingStateParser<typeof vendorCandidates.$inferSelect>().withDefault([
{ id: "createdAt", desc: true },
]),
// Advanced filter
filters: getFiltersStateParser().withDefault([]),
joinOperator: parseAsStringEnum(["and", "or"]).withDefault("and"),
// Global search
search: parseAsString.withDefault(""),
// -----------------------------------------------------------------
// Fields specific to vendor investigations
// -----------------------------------------------------------------
// investigationStatus: PLANNED, IN_PROGRESS, COMPLETED, CANCELED
status: parseAsStringEnum(["COLLECTED", "INVITED", "DISCARDED"]),
// In case you also want to filter by vendorName, vendorCode, etc.
companyName: parseAsString.withDefault(""),
contactEmail: parseAsString.withDefault(""),
contactPhone: parseAsString.withDefault(""),
country: parseAsString.withDefault(""),
source: parseAsString.withDefault(""),
})
// Finally, export the type you can use in your server action:
export type GetVendorsCandidateSchema = Awaited<ReturnType<typeof searchParamsCandidateCache.parse>>
// Updated version of the updateVendorCandidateSchema
export const updateVendorCandidateSchema = z.object({
id: z.number(),
companyName: z.string().min(1).max(255).optional(),
contactEmail: z.string().email().max(255).optional(),
contactPhone: z.string().max(50).optional(),
country: z.string().max(100).optional(),
source: z.string().max(100).optional(),
status: z.enum(["COLLECTED", "INVITED", "DISCARDED"]).optional(),
updatedAt: z.date().optional().default(() => new Date()),
});
// Create schema for vendor candidates
export const createVendorCandidateSchema = z.object({
companyName: z.string().min(1).max(255),
contactEmail: z.string().email().max(255),
contactPhone: z.string().max(50).optional(),
country: z.string().max(100).optional(),
source: z.string().max(100).optional(),
status: z.enum(["COLLECTED", "INVITED", "DISCARDED"]).default("COLLECTED"),
});
// Export types for both schemas
export type UpdateVendorCandidateSchema = z.infer<typeof updateVendorCandidateSchema>;
export type CreateVendorCandidateSchema = z.infer<typeof createVendorCandidateSchema>;
export const removeCandidatesSchema = z.object({
ids: z.array(z.number()).min(1, "At least one candidate ID must be provided"),
});
export type RemoveCandidatesInput = z.infer<typeof removeCandidatesSchema>;
|