Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions components/groups/endpoints/create-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { zodResolver } from "@hookform/resolvers/zod";
import * as z from "zod";
import { useFieldArray, useForm } from "react-hook-form";

import { validationOptions } from "@/lib/validation";
import { normalizedValidationOption, validationOptions } from "@/lib/validation";
import { createEndpointFormSchema as formSchema } from "@/lib/data/validations";

// next imports
Expand Down Expand Up @@ -136,7 +136,7 @@ export default function CreateForm() {
<SelectContent>
{validationOptions.map((type, index: number) => (
<SelectItem key={index} value={type.name}>
{type.name}
{normalizedValidationOption[type.name]}
</SelectItem>
))}
</SelectContent>
Expand Down
4 changes: 2 additions & 2 deletions components/groups/endpoints/edit-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as z from "zod";
import { useFieldArray, useForm } from "react-hook-form";
import { updateEndpointFormSchema as formSchema } from "@/lib/data/validations";

import { validationOptions } from "@/lib/validation";
import { normalizedValidationOption, validationOptions } from "@/lib/validation";

// next imports
import { useRouter } from "next/navigation";
Expand Down Expand Up @@ -143,7 +143,7 @@ export default function EditForm({
<SelectContent>
{validationOptions.map((type, index: number) => (
<SelectItem key={index} value={type.name}>
{type.name}
{normalizedValidationOption[type.name]}
</SelectItem>
))}
</SelectContent>
Expand Down
18 changes: 18 additions & 0 deletions lib/validation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import validator from "validator";
* 1. add a key value pair in 'validationOptions' of the new validation type
* 2. Add a zod schema definition in the 'validations' object in this file
* 3. If necessary, add respective logic to correct / cast the type in the 'convertToCorrectTypes' function
* 4. Add the normalized name of the validation type in the 'normalizedValidationOption' object
*/
export const validationOptions: { name: ValidationType }[] = [
{ name: "phone" },
Expand All @@ -21,6 +22,23 @@ export const validationOptions: { name: ValidationType }[] = [
{ name: "zip_code" },
];

/**
* The normalized validation types available
*
* Add a new entry to this when adding a new validation option to the 'validationOptions' array
*/

export const normalizedValidationOption = {
phone: "Phone Number",
email: "E-Mail Address",
string: "String",
number: "Number",
date: "Date",
boolean: "Boolean",
url: "URL",
zip_code: "Zip Code",
}

/**
* Zod validations for each validation type
*
Expand Down