diff --git a/app/(protected)/dashboard/records/record-list.tsx b/app/(protected)/dashboard/records/record-list.tsx index d618e23..df419c7 100644 --- a/app/(protected)/dashboard/records/record-list.tsx +++ b/app/(protected)/dashboard/records/record-list.tsx @@ -6,8 +6,8 @@ import { User } from "@prisma/client"; import { PenLine, RefreshCwIcon } from "lucide-react"; import useSWR, { useSWRConfig } from "swr"; -import { TTL_ENUMS } from "@/lib/cloudflare"; import { UserRecordFormData } from "@/lib/dto/cloudflare-dns-record"; +import { TTL_ENUMS } from "@/lib/enums"; import { fetcher } from "@/lib/utils"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; diff --git a/app/(protected)/dashboard/urls/url-list.tsx b/app/(protected)/dashboard/urls/url-list.tsx index 98552a0..31b7a1a 100644 --- a/app/(protected)/dashboard/urls/url-list.tsx +++ b/app/(protected)/dashboard/urls/url-list.tsx @@ -7,7 +7,7 @@ import { PenLine, RefreshCwIcon } from "lucide-react"; import useSWR, { useSWRConfig } from "swr"; import { siteConfig } from "@/config/site"; -import { EXPIRATION_ENUMS, ShortUrlFormData } from "@/lib/dto/short-urls"; +import { ShortUrlFormData } from "@/lib/dto/short-urls"; import { cn, expirationTime, fetcher, timeAgo } from "@/lib/utils"; import { useMediaQuery } from "@/hooks/use-media-query"; import { Button } from "@/components/ui/button"; diff --git a/auth.config.ts b/auth.config.ts index 36041b6..1faf817 100644 --- a/auth.config.ts +++ b/auth.config.ts @@ -5,11 +5,6 @@ import Resend from "next-auth/providers/resend"; import { env } from "@/env.mjs"; -// import { siteConfig } from "@/config/site" -// import { getUserByEmail } from "@/lib/user"; -// import MagicLinkEmail from "@/emails/magic-link-email" -// import { prisma } from "@/lib/db" - export default { providers: [ Google({ diff --git a/components/forms/record-form.tsx b/components/forms/record-form.tsx index 1f106da..291ac7a 100644 --- a/components/forms/record-form.tsx +++ b/components/forms/record-form.tsx @@ -6,13 +6,9 @@ import { User } from "@prisma/client"; import { useForm } from "react-hook-form"; import { toast } from "sonner"; -import { - CreateDNSRecord, - RECORD_TYPE_ENUMS, - RecordType, - TTL_ENUMS, -} from "@/lib/cloudflare"; +import { CreateDNSRecord, RecordType } from "@/lib/cloudflare"; import { UserRecordFormData } from "@/lib/dto/cloudflare-dns-record"; +import { RECORD_TYPE_ENUMS, TTL_ENUMS } from "@/lib/enums"; import { createRecordSchema } from "@/lib/validations/record"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; @@ -260,7 +256,7 @@ export function RecordForm({ setValue("ttl", Number(value)); }} name="ttl" - defaultValue={`${initData?.ttl}` || "1"} + defaultValue={String(initData?.ttl || 1)} > diff --git a/components/forms/url-form.tsx b/components/forms/url-form.tsx index ece7232..68686c7 100644 --- a/components/forms/url-form.tsx +++ b/components/forms/url-form.tsx @@ -7,7 +7,8 @@ import { Sparkles } from "lucide-react"; import { useForm } from "react-hook-form"; import { toast } from "sonner"; -import { EXPIRATION_ENUMS, ShortUrlFormData } from "@/lib/dto/short-urls"; +import { ShortUrlFormData } from "@/lib/dto/short-urls"; +import { EXPIRATION_ENUMS } from "@/lib/enums"; import { generateUrlSuffix } from "@/lib/utils"; import { createUrlSchema } from "@/lib/validations/url"; import { Button } from "@/components/ui/button"; diff --git a/components/forms/user-form.tsx b/components/forms/user-form.tsx index d1442f2..b6de11a 100644 --- a/components/forms/user-form.tsx +++ b/components/forms/user-form.tsx @@ -6,7 +6,7 @@ import { User, UserRole } from "@prisma/client"; import { useForm } from "react-hook-form"; import { toast } from "sonner"; -import { ROLE_ENUM } from "@/lib/dto/user"; +import { ROLE_ENUM } from "@/lib/enums"; import { updateUserSchema } from "@/lib/validations/auth"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; diff --git a/lib/cloudflare.ts b/lib/cloudflare.ts index 6284e2d..7945bdb 100644 --- a/lib/cloudflare.ts +++ b/lib/cloudflare.ts @@ -54,49 +54,6 @@ export interface ResultMeta { export type RecordType = "A" | "CNAME"; -export const RECORD_TYPE_ENUMS = [ - { - value: "CNAME", - label: "CNAME", - }, - { - value: "A", - label: "A", - }, -]; -export const TTL_ENUMS = [ - { - value: "1", - label: "Auto", - }, - { - value: "300", - label: "5min", - }, - { - value: "3600", - label: "1h", - }, - { - value: "18000", - label: "5h", - }, - { - value: "86400", - label: "1d", - }, -]; -export const STATUS_ENUMS = [ - { - value: 1, - label: "Active", - }, - { - value: 0, - label: "Inactive", - }, -]; - export const createDNSRecord = async ( zoneId: string, apiKey: string, diff --git a/lib/dto/short-urls.ts b/lib/dto/short-urls.ts index f38af3c..bea1cc6 100644 --- a/lib/dto/short-urls.ts +++ b/lib/dto/short-urls.ts @@ -21,45 +21,6 @@ export interface UserShortUrlInfo extends ShortUrlFormData { meta?: UrlMeta; } -export const EXPIRATION_ENUMS = [ - { - value: "-1", - label: "Never", - }, - { - value: "600", // 10 min - label: "10min", - }, - { - value: "3600", // 1h - label: "1h", - }, - { - value: "43200", // 12h - label: "12h", - }, - { - value: "86400", // 1d - label: "1d", - }, - { - value: "604800", // 7d - label: "7d", - }, - { - value: "2592000", // 30d - label: "30d", - }, - { - value: "7776000", // 90d - label: "90d", - }, - { - value: "31536000", // 365d - label: "365d", - }, -]; - export async function getUserShortUrls( userId: string, active: number = 1, diff --git a/lib/dto/user.ts b/lib/dto/user.ts index 2811ece..2d2399e 100644 --- a/lib/dto/user.ts +++ b/lib/dto/user.ts @@ -4,17 +4,6 @@ import { prisma } from "@/lib/db"; export interface UpdateUserForm extends Omit {} -export const ROLE_ENUM = [ - { - label: "User", - value: "USER", - }, - { - label: "Admin", - value: "ADMIN", - }, -]; - export const getUserByEmail = async (email: string) => { try { const user = await prisma.user.findUnique({ diff --git a/lib/enums.ts b/lib/enums.ts new file mode 100644 index 0000000..53bf75f --- /dev/null +++ b/lib/enums.ts @@ -0,0 +1,92 @@ +export const EXPIRATION_ENUMS = [ + { + value: "-1", + label: "Never", + }, + { + value: "600", // 10 min + label: "10min", + }, + { + value: "3600", // 1h + label: "1h", + }, + { + value: "43200", // 12h + label: "12h", + }, + { + value: "86400", // 1d + label: "1d", + }, + { + value: "604800", // 7d + label: "7d", + }, + { + value: "2592000", // 30d + label: "30d", + }, + { + value: "7776000", // 90d + label: "90d", + }, + { + value: "31536000", // 365d + label: "365d", + }, +]; + +export const ROLE_ENUM = [ + { + label: "User", + value: "USER", + }, + { + label: "Admin", + value: "ADMIN", + }, +]; + +export const RECORD_TYPE_ENUMS = [ + { + value: "CNAME", + label: "CNAME", + }, + { + value: "A", + label: "A", + }, +]; +export const TTL_ENUMS = [ + { + value: "1", + label: "Auto", + }, + { + value: "300", + label: "5min", + }, + { + value: "3600", + label: "1h", + }, + { + value: "18000", + label: "5h", + }, + { + value: "86400", + label: "1d", + }, +]; +export const STATUS_ENUMS = [ + { + value: 1, + label: "Active", + }, + { + value: 0, + label: "Inactive", + }, +];