fix: set workspaceId on new board
This commit is contained in:
@@ -8,6 +8,7 @@ import { FaTrello } from "react-icons/fa";
|
||||
import { HiChevronUpDown, HiXMark } from "react-icons/hi2";
|
||||
|
||||
import { useModal } from "~/app/providers/modal";
|
||||
import { useWorkspace } from "~/app/providers/workspace";
|
||||
|
||||
import { useFormik } from "formik";
|
||||
|
||||
@@ -102,6 +103,7 @@ const ImportTrello: React.FC = () => {
|
||||
const [apiKey, setApiKey] = useState("");
|
||||
const [token, setToken] = useState("");
|
||||
const { closeModal } = useModal();
|
||||
const { workspace } = useWorkspace();
|
||||
|
||||
const refetchBoards = () => utils.board.all.refetch();
|
||||
|
||||
@@ -153,6 +155,7 @@ const ImportTrello: React.FC = () => {
|
||||
boardIds,
|
||||
apiKey: formik.values.apiKey,
|
||||
token: formik.values.token,
|
||||
workspacePublicId: workspace?.publicId,
|
||||
});
|
||||
},
|
||||
enableReinitialize: true,
|
||||
|
||||
@@ -5,6 +5,7 @@ import { api } from "~/trpc/react";
|
||||
import { HiXMark } from "react-icons/hi2";
|
||||
|
||||
import { useModal } from "~/app/providers/modal";
|
||||
import { useWorkspace } from "~/app/providers/workspace";
|
||||
|
||||
import { Formik, Form, Field } from "formik";
|
||||
|
||||
@@ -15,6 +16,7 @@ interface FormValues {
|
||||
export function NewBoardForm() {
|
||||
const utils = api.useUtils();
|
||||
const { closeModal } = useModal();
|
||||
const { workspace } = useWorkspace();
|
||||
|
||||
const refetchBoards = () => utils.board.all.refetch();
|
||||
|
||||
@@ -44,6 +46,7 @@ export function NewBoardForm() {
|
||||
onSubmit={(values: FormValues) => {
|
||||
createBoard.mutate({
|
||||
name: values.name,
|
||||
workspacePublicId: workspace?.publicId,
|
||||
});
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -90,17 +90,27 @@ export const boardRouter = createTRPCRouter({
|
||||
.input(
|
||||
z.object({
|
||||
name: z.string().min(1),
|
||||
workspacePublicId: z.string().min(12)
|
||||
}),
|
||||
)
|
||||
.mutation(({ ctx, input }) => {
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const userId = ctx.session?.user.id;
|
||||
|
||||
if (!userId) return;
|
||||
|
||||
const workspace = await ctx.db.query.workspaces.findFirst({
|
||||
where: eq(workspaces.publicId, input.workspacePublicId),
|
||||
})
|
||||
|
||||
console.log({ workspace })
|
||||
|
||||
if (!workspace) return;
|
||||
|
||||
return ctx.db.insert(boards).values({
|
||||
publicId: generateUID(),
|
||||
name: input.name,
|
||||
createdBy: userId,
|
||||
workspaceId: workspace.id
|
||||
});
|
||||
}),
|
||||
update: publicProcedure
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
publicProcedure,
|
||||
} from "~/server/api/trpc";
|
||||
|
||||
import { boards, cards, imports, lists } from "~/server/db/schema";
|
||||
import { boards, cards, imports, lists, workspaces } from "~/server/db/schema";
|
||||
import { generateUID } from "~/utils/generateUID";
|
||||
|
||||
const TRELLO_API_URL = 'https://api.trello.com/1';
|
||||
@@ -81,6 +81,7 @@ export const importRouter = createTRPCRouter({
|
||||
boardIds: z.array(z.string()),
|
||||
apiKey: z.string().length(32),
|
||||
token: z.string().length(76),
|
||||
workspacePublicId: z.string().min(12)
|
||||
}),
|
||||
)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
@@ -114,12 +115,19 @@ export const importRouter = createTRPCRouter({
|
||||
}))
|
||||
}
|
||||
|
||||
const workspace = await ctx.db.query.workspaces.findFirst({
|
||||
where: eq(workspaces.publicId, input.workspacePublicId),
|
||||
})
|
||||
|
||||
if (!workspace) return;
|
||||
|
||||
await ctx.db.transaction(async (tx) => {
|
||||
const newBoard = await tx.insert(boards).values({
|
||||
publicId: generateUID(),
|
||||
name: data.name,
|
||||
createdBy: userId,
|
||||
importId: newImport.insertId
|
||||
importId: newImport.insertId,
|
||||
workspaceId: workspace.id
|
||||
});
|
||||
|
||||
if (!newBoard?.insertId) return;
|
||||
|
||||
Reference in New Issue
Block a user