diff --git a/apps/web/next.config.js b/apps/web/next.config.js index 65c2d8e7..6d8f2935 100644 --- a/apps/web/next.config.js +++ b/apps/web/next.config.js @@ -9,7 +9,7 @@ const config = { reactStrictMode: true, /** Enables hot reloading for local packages without a build step */ - transpilePackages: ["@kan/api", "@kan/db", "@kan/utils"], + transpilePackages: ["@kan/api", "@kan/db", "@kan/shared"], /** We already do linting and typechecking as separate tasks in CI */ eslint: { ignoreDuringBuilds: true }, diff --git a/apps/web/package.json b/apps/web/package.json index 20f448b1..cd96c3c7 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -18,8 +18,8 @@ "@hookform/resolvers": "^3.3.4", "@kan/api": "workspace:*", "@kan/db": "workspace:^", + "@kan/shared": "workspace:^", "@kan/supabase": "workspace:^", - "@kan/utils": "workspace:^", "@t3-oss/env-nextjs": "^0.11.1", "@tanstack/react-query": "catalog:", "@trpc/client": "catalog:", diff --git a/apps/web/src/providers/board.tsx b/apps/web/src/providers/board.tsx index 7c68b5be..4e374f3f 100644 --- a/apps/web/src/providers/board.tsx +++ b/apps/web/src/providers/board.tsx @@ -8,7 +8,7 @@ import type { ReorderCardInput, ReorderListInput, } from "@kan/api/types"; -import { generateUID } from "@kan/utils"; +import { generateUID } from "@kan/shared/utils"; import { usePopup } from "~/providers/popup"; import { api } from "~/utils/api"; diff --git a/apps/web/src/views/card/components/LabelForm.tsx b/apps/web/src/views/card/components/LabelForm.tsx index 90270ea4..384ace91 100644 --- a/apps/web/src/views/card/components/LabelForm.tsx +++ b/apps/web/src/views/card/components/LabelForm.tsx @@ -1,36 +1,26 @@ -import { Fragment } from "react"; -import { HiChevronUpDown, HiXMark } from "react-icons/hi2"; -import { useForm, Controller } from "react-hook-form"; import { Listbox, Transition } from "@headlessui/react"; +import { Fragment } from "react"; +import { Controller, useForm } from "react-hook-form"; +import { HiChevronUpDown, HiXMark } from "react-icons/hi2"; -import { api } from "~/utils/api"; -import { useModal } from "~/providers/modal"; +import { colours } from "@kan/shared/constants"; import Button from "~/components/Button"; import Input from "~/components/Input"; import Toggle from "~/components/Toggle"; +import { useModal } from "~/providers/modal"; +import { api } from "~/utils/api"; -type LabelFormInput = { +interface LabelFormInput { name: string; colour: Colour; isCreateAnotherEnabled?: boolean; -}; +} -type Colour = { +interface Colour { name: string; code: string; -}; - -const colours = [ - { name: "Teal", code: "#0d9488" }, - { name: "Green", code: "#65a30d" }, - { name: "Blue", code: "#0284c7" }, - { name: "Purple", code: "#4f46e5" }, - { name: "Yellow", code: "#ca8a04" }, - { name: "Orange", code: "#ea580c" }, - { name: "Red", code: "#dc2626" }, - { name: "Pink", code: "#db2777" }, -]; +} export function LabelForm({ cardPublicId, @@ -54,9 +44,9 @@ export function LabelForm({ const { control, register, reset, handleSubmit, setValue, watch } = useForm({ values: { - name: isEdit && label?.data?.name ? label?.data?.name : "", - colour: (isEdit && label?.data?.colourCode - ? colours.find((c) => c.code === label?.data?.colourCode) + name: isEdit && label.data?.name ? label.data.name : "", + colour: (isEdit && label.data?.colourCode + ? colours.find((c) => c.code === label.data?.colourCode) : colours[0]) as Colour, isCreateAnotherEnabled: false, }, @@ -97,7 +87,7 @@ export function LabelForm({ }); const onSubmit = (values: LabelFormInput) => { - if (!values.colour?.code) return; + if (!values.colour.code) return; if (isEdit) { updateLabel.mutate({ @@ -144,11 +134,11 @@ export function LabelForm({ - {field.value?.name} + {field.value.name} @@ -170,7 +160,7 @@ export function LabelForm({ {colours.map((colour, index) => ( {() => ( diff --git a/packages/api/package.json b/packages/api/package.json index a788d6c9..4f01f517 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -37,8 +37,8 @@ "dependencies": { "@kan/db": "workspace:*", "@kan/email": "workspace:^", + "@kan/shared": "workspace:^", "@kan/supabase": "workspace:^", - "@kan/utils": "workspace:^", "@trpc/server": "catalog:", "superjson": "2.2.1", "trpc-to-openapi": "^2.1.0", diff --git a/packages/api/src/routers/board.ts b/packages/api/src/routers/board.ts index 7b96ad80..b17963cc 100644 --- a/packages/api/src/routers/board.ts +++ b/packages/api/src/routers/board.ts @@ -6,7 +6,7 @@ import * as cardRepo from "@kan/db/repository/card.repo"; import * as activityRepo from "@kan/db/repository/cardActivity.repo"; import * as listRepo from "@kan/db/repository/list.repo"; import * as workspaceRepo from "@kan/db/repository/workspace.repo"; -import { generateSlug, generateUID } from "@kan/utils"; +import { generateSlug, generateUID } from "@kan/shared/utils"; import { createTRPCRouter, protectedProcedure, publicProcedure } from "../trpc"; diff --git a/packages/api/src/routers/workspace.ts b/packages/api/src/routers/workspace.ts index 3bf34ee1..36b50fd9 100644 --- a/packages/api/src/routers/workspace.ts +++ b/packages/api/src/routers/workspace.ts @@ -3,7 +3,7 @@ import { z } from "zod"; import * as workspaceRepo from "@kan/db/repository/workspace.repo"; import * as workspaceSlugRepo from "@kan/db/repository/workspaceSlug.repo"; -import { generateUID } from "@kan/utils"; +import { generateUID } from "@kan/shared/utils"; import { createTRPCRouter, protectedProcedure, publicProcedure } from "../trpc"; diff --git a/packages/db/package.json b/packages/db/package.json index a80ae588..b9d9e1f4 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -38,7 +38,7 @@ "with-env": "dotenv -e ../../.env --" }, "dependencies": { - "@kan/utils": "workspace:^", + "@kan/shared": "workspace:^", "@vercel/postgres": "^0.10.0", "drizzle-orm": "^0.36.4", "drizzle-zod": "^0.5.1", diff --git a/packages/db/src/repository/board.repo.ts b/packages/db/src/repository/board.repo.ts index 9225810f..9e426e77 100644 --- a/packages/db/src/repository/board.repo.ts +++ b/packages/db/src/repository/board.repo.ts @@ -1,7 +1,7 @@ import type { SupabaseClient } from "@supabase/supabase-js"; import type { Database } from "@kan/db/types/database.types"; -import { generateUID } from "@kan/utils"; +import { generateUID } from "@kan/shared/utils"; export const getAllByWorkspaceId = async ( db: SupabaseClient, diff --git a/packages/db/src/repository/card.repo.ts b/packages/db/src/repository/card.repo.ts index 67cd08a2..eaa0cced 100644 --- a/packages/db/src/repository/card.repo.ts +++ b/packages/db/src/repository/card.repo.ts @@ -1,7 +1,7 @@ import type { SupabaseClient } from "@supabase/supabase-js"; import type { Database } from "@kan/db/types/database.types"; -import { generateUID } from "@kan/utils"; +import { generateUID } from "@kan/shared/utils"; export const create = async ( db: SupabaseClient, diff --git a/packages/db/src/repository/cardActivity.repo.ts b/packages/db/src/repository/cardActivity.repo.ts index 3b564c20..28e88d69 100644 --- a/packages/db/src/repository/cardActivity.repo.ts +++ b/packages/db/src/repository/cardActivity.repo.ts @@ -1,7 +1,7 @@ import type { SupabaseClient } from "@supabase/supabase-js"; import type { Database } from "@kan/db/types/database.types"; -import { generateUID } from "@kan/utils"; +import { generateUID } from "@kan/shared/utils"; export const create = async ( db: SupabaseClient, diff --git a/packages/db/src/repository/cardComment.repo.ts b/packages/db/src/repository/cardComment.repo.ts index 53737fac..8df47a2b 100644 --- a/packages/db/src/repository/cardComment.repo.ts +++ b/packages/db/src/repository/cardComment.repo.ts @@ -1,7 +1,7 @@ import type { SupabaseClient } from "@supabase/supabase-js"; import type { Database } from "@kan/db/types/database.types"; -import { generateUID } from "@kan/utils"; +import { generateUID } from "@kan/shared/utils"; export const create = async ( db: SupabaseClient, diff --git a/packages/db/src/repository/list.repo.ts b/packages/db/src/repository/list.repo.ts index 381c16f7..6c7ea799 100644 --- a/packages/db/src/repository/list.repo.ts +++ b/packages/db/src/repository/list.repo.ts @@ -1,7 +1,7 @@ import type { SupabaseClient } from "@supabase/supabase-js"; import type { Database } from "@kan/db/types/database.types"; -import { generateUID } from "@kan/utils"; +import { generateUID } from "@kan/shared/utils"; export const create = async ( db: SupabaseClient, diff --git a/packages/db/src/repository/member.repo.ts b/packages/db/src/repository/member.repo.ts index cf62c0d1..fcf47c1e 100644 --- a/packages/db/src/repository/member.repo.ts +++ b/packages/db/src/repository/member.repo.ts @@ -1,7 +1,7 @@ import type { SupabaseClient } from "@supabase/supabase-js"; import type { Database } from "@kan/db/types/database.types"; -import { generateUID } from "@kan/utils"; +import { generateUID } from "@kan/shared/utils"; export const create = async ( db: SupabaseClient, diff --git a/packages/db/src/repository/workspace.repo.ts b/packages/db/src/repository/workspace.repo.ts index a842fd9a..a1f862e8 100644 --- a/packages/db/src/repository/workspace.repo.ts +++ b/packages/db/src/repository/workspace.repo.ts @@ -1,7 +1,7 @@ import type { SupabaseClient } from "@supabase/supabase-js"; import type { Database } from "@kan/db/types/database.types"; -import { generateUID } from "@kan/utils"; +import { generateUID } from "@kan/shared/utils"; export const create = async ( db: SupabaseClient, diff --git a/packages/utils/eslint.config.js b/packages/shared/eslint.config.js similarity index 100% rename from packages/utils/eslint.config.js rename to packages/shared/eslint.config.js diff --git a/packages/utils/package.json b/packages/shared/package.json similarity index 67% rename from packages/utils/package.json rename to packages/shared/package.json index 60d02444..f0df58bf 100644 --- a/packages/utils/package.json +++ b/packages/shared/package.json @@ -1,10 +1,21 @@ { - "name": "@kan/utils", + "name": "@kan/shared", "private": true, "version": "0.1.0", "type": "module", "exports": { - ".": "./src/index.ts" + ".": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + }, + "./utils": { + "types": "./dist/utils/index.d.ts", + "default": "./dist/utils/index.js" + }, + "./constants": { + "types": "./dist/constants/index.d.ts", + "default": "./dist/constants/index.js" + } }, "license": "MIT", "scripts": { diff --git a/packages/shared/src/constants/colours.ts b/packages/shared/src/constants/colours.ts new file mode 100644 index 00000000..de851f47 --- /dev/null +++ b/packages/shared/src/constants/colours.ts @@ -0,0 +1,12 @@ +export const colours: { name: string; code: string }[] = [ + { name: "Teal", code: "#0d9488" }, + { name: "Green", code: "#65a30d" }, + { name: "Blue", code: "#0284c7" }, + { name: "Purple", code: "#4f46e5" }, + { name: "Yellow", code: "#ca8a04" }, + { name: "Orange", code: "#ea580c" }, + { name: "Red", code: "#dc2626" }, + { name: "Pink", code: "#db2777" }, +] as const; + +export type Colour = (typeof colours)[number]; diff --git a/packages/shared/src/constants/index.ts b/packages/shared/src/constants/index.ts new file mode 100644 index 00000000..18a20ee5 --- /dev/null +++ b/packages/shared/src/constants/index.ts @@ -0,0 +1 @@ +export * from "./colours"; diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts new file mode 100644 index 00000000..3df3f1aa --- /dev/null +++ b/packages/shared/src/index.ts @@ -0,0 +1,4 @@ +export const name = "shared"; + +export * from "./constants"; +export * from "./utils"; diff --git a/packages/utils/src/generateSlug.ts b/packages/shared/src/utils/generateSlug.ts similarity index 100% rename from packages/utils/src/generateSlug.ts rename to packages/shared/src/utils/generateSlug.ts diff --git a/packages/utils/src/generateUID.ts b/packages/shared/src/utils/generateUID.ts similarity index 100% rename from packages/utils/src/generateUID.ts rename to packages/shared/src/utils/generateUID.ts diff --git a/packages/shared/src/utils/index.ts b/packages/shared/src/utils/index.ts new file mode 100644 index 00000000..64c9bd95 --- /dev/null +++ b/packages/shared/src/utils/index.ts @@ -0,0 +1,2 @@ +export * from "./generateUID"; +export * from "./generateSlug"; diff --git a/packages/utils/tsconfig.json b/packages/shared/tsconfig.json similarity index 100% rename from packages/utils/tsconfig.json rename to packages/shared/tsconfig.json diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts deleted file mode 100644 index bb2edd45..00000000 --- a/packages/utils/src/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export const name = "utils"; - -export { generateUID } from "./generateUID"; -export { generateSlug } from "./generateSlug"; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 528e8216..3fc47c9c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -87,12 +87,12 @@ importers: '@kan/db': specifier: workspace:^ version: link:../../packages/db + '@kan/shared': + specifier: workspace:^ + version: link:../../packages/shared '@kan/supabase': specifier: workspace:^ version: link:../../packages/supabase - '@kan/utils': - specifier: workspace:^ - version: link:../../packages/utils '@t3-oss/env-nextjs': specifier: ^0.11.1 version: 0.11.1(typescript@5.7.2)(zod@3.24.0) @@ -214,12 +214,12 @@ importers: '@kan/email': specifier: workspace:^ version: link:../email + '@kan/shared': + specifier: workspace:^ + version: link:../shared '@kan/supabase': specifier: workspace:^ version: link:../supabase - '@kan/utils': - specifier: workspace:^ - version: link:../utils '@trpc/server': specifier: 'catalog:' version: 11.0.0-rc.660(typescript@5.7.2) @@ -254,9 +254,9 @@ importers: packages/db: dependencies: - '@kan/utils': + '@kan/shared': specifier: workspace:^ - version: link:../utils + version: link:../shared '@vercel/postgres': specifier: ^0.10.0 version: 0.10.0(utf-8-validate@6.0.3) @@ -323,6 +323,31 @@ importers: specifier: 'catalog:' version: 5.7.2 + packages/shared: + dependencies: + nanoid: + specifier: ^5.0.9 + version: 5.0.9 + devDependencies: + '@kan/eslint-config': + specifier: workspace:* + version: link:../../tooling/eslint + '@kan/prettier-config': + specifier: workspace:* + version: link:../../tooling/prettier + '@kan/tsconfig': + specifier: workspace:* + version: link:../../tooling/typescript + eslint: + specifier: 'catalog:' + version: 9.16.0(jiti@1.21.6) + prettier: + specifier: 'catalog:' + version: 3.4.2 + typescript: + specifier: 'catalog:' + version: 5.7.2 + packages/supabase: dependencies: '@edge-runtime/cookies': @@ -360,31 +385,6 @@ importers: specifier: 'catalog:' version: 5.7.2 - packages/utils: - dependencies: - nanoid: - specifier: ^5.0.9 - version: 5.0.9 - devDependencies: - '@kan/eslint-config': - specifier: workspace:* - version: link:../../tooling/eslint - '@kan/prettier-config': - specifier: workspace:* - version: link:../../tooling/prettier - '@kan/tsconfig': - specifier: workspace:* - version: link:../../tooling/typescript - eslint: - specifier: 'catalog:' - version: 9.16.0(jiti@1.21.6) - prettier: - specifier: 'catalog:' - version: 3.4.2 - typescript: - specifier: 'catalog:' - version: 5.7.2 - tooling/eslint: dependencies: '@eslint/compat':