chore: clean up type errors and warnings

This commit is contained in:
Henry
2024-07-24 16:05:40 +01:00
parent bfd23406dd
commit d334607a9c
11 changed files with 178 additions and 50 deletions

View File

@@ -8,9 +8,9 @@ import React, {
import { api } from "~/utils/api";
import {
GetBoardByIdOutput,
ReorderCardInput,
ReorderListInput,
type GetBoardByIdOutput,
type ReorderCardInput,
type ReorderListInput,
} from "~/types/router.types";
interface BoardContextProps {
@@ -40,29 +40,22 @@ export const BoardProvider: React.FC<{ children: ReactNode }> = ({
const [boardData, setBoardData] =
useState<GetBoardByIdOutput>(initialBoardData);
const refetchBoard = () => {
if (boardData?.publicId)
utils.board.byId.refetch({ boardPublicId: boardData.publicId });
const refetchBoard = async () => {
if (boardData?.publicId) {
try {
await utils.board.byId.refetch({ boardPublicId: boardData.publicId });
} catch (e) {
console.error(e);
}
}
};
const updateCardMutation = api.card.reorder.useMutation({
onSuccess: async () => {
try {
await refetchBoard();
} catch (e) {
console.log(e);
}
},
onSuccess: () => refetchBoard(),
});
const updateListMutation = api.list.reorder.useMutation({
onSuccess: async () => {
try {
await refetchBoard();
} catch (e) {
console.log(e);
}
},
onSuccess: () => refetchBoard(),
});
const updateList = ({

View File

@@ -195,7 +195,7 @@ export const cardRouter = createTRPCRouter({
input.cardPublicId,
);
if (!card || !card?.list?.id) return;
if (!card ?? !card?.list?.id) return;
const deletedAt = new Date().toISOString();

View File

@@ -105,5 +105,7 @@ export const listRouter = createTRPCRouter({
{ name: input.name },
{ listPublicId: input.listPublicId },
);
return result;
}),
});

View File

@@ -1,5 +1,4 @@
import { z } from "zod";
import { generateUID } from "~/utils/generateUID";
import { createTRPCRouter, protectedProcedure } from "~/server/api/trpc";
import * as workspaceRepo from "~/server/db/repository/workspace.repo";

View File

@@ -1,4 +1,4 @@
import { RouterInputs, type RouterOutputs } from "~/utils/api";
import { type RouterInputs, type RouterOutputs } from "~/utils/api";
export type GetBoardByIdOutput = RouterOutputs["board"]["byId"];
export type ReorderListInput = RouterInputs["list"]["reorder"];

View File

@@ -13,15 +13,20 @@ export function DeleteListConfirmation({
const { boardData } = useBoard();
const { closeModal } = useModal();
const refetchBoard = () => {
if (boardData?.publicId)
utils.board.byId.refetch({ boardPublicId: boardData.publicId });
const refetchBoard = async () => {
if (boardData?.publicId) {
try {
await utils.board.byId.refetch({ boardPublicId: boardData.publicId });
} catch (e) {
console.error(e);
}
}
};
const deleteList = api.list.delete.useMutation({
onSuccess: async () => {
onSuccess: () => {
closeModal();
await refetchBoard();
return refetchBoard();
},
});

View File

@@ -9,7 +9,7 @@ import CheckboxDropdown from "~/components/CheckboxDropdown";
import { useBoard } from "~/providers/board";
import { useModal } from "~/providers/modal";
import { NewCardInput } from "~/types/router.types";
import { type NewCardInput } from "~/types/router.types";
type NewCardFormInput = NewCardInput & {
isCreateAnotherEnabled: boolean;
@@ -43,9 +43,14 @@ export function NewCardForm({ listPublicId }: NewCardFormProps) {
const memberPublicIds = watch("memberPublicIds") || [];
const isCreateAnotherEnabled = watch("isCreateAnotherEnabled");
const refetchBoard = () => {
if (boardData?.publicId)
utils.board.byId.refetch({ boardPublicId: boardData.publicId });
const refetchBoard = async () => {
if (boardData?.publicId) {
try {
await utils.board.byId.refetch({ boardPublicId: boardData.publicId });
} catch (e) {
console.error(e);
}
}
};
const createCard = api.card.create.useMutation({

View File

@@ -7,7 +7,7 @@ import { Switch } from "@headlessui/react";
import { useBoard } from "~/providers/board";
import { useModal } from "~/providers/modal";
import { NewListInput } from "~/types/router.types";
import { type NewListInput } from "~/types/router.types";
import { Formik, Form, Field } from "formik";
@@ -21,16 +21,21 @@ export function NewListForm({ boardPublicId }: { boardPublicId: string }) {
const { closeModal } = useModal();
const [isCreateAnotherEnabled, setIsCreateAnotherEnabled] = useState(false);
const refetchBoard = () => {
if (boardData?.publicId)
utils.board.byId.refetch({ boardPublicId: boardData.publicId });
const refetchBoard = async () => {
if (boardData?.publicId) {
try {
await utils.board.byId.refetch({ boardPublicId: boardData.publicId });
} catch (e) {
console.error(e);
}
}
};
const createList = api.list.create.useMutation({
onSuccess: async () => {
onSuccess: () => {
try {
await refetchBoard();
if (!isCreateAnotherEnabled) closeModal();
return refetchBoard();
} catch (e) {
console.log(e);
}

View File

@@ -25,7 +25,7 @@ import { NewWorkspaceForm } from "~/components/NewWorkspaceForm";
import { NewCardForm } from "./components/NewCardForm";
import { NewListForm } from "./components/NewListForm";
import { UpdateBoardInput } from "~/types/router.types";
import { type UpdateBoardInput } from "~/types/router.types";
type PublicListId = string;
@@ -228,7 +228,7 @@ export default function BoardPage() {
>
<svg
fill={
label.colourCode || undefined
label.colourCode ?? undefined
}
className="h-2 w-2"
viewBox="0 0 6 6"
@@ -246,15 +246,14 @@ export default function BoardPage() {
className="inline-flex h-6 w-6 items-center justify-center rounded-full bg-light-900 ring-2 ring-light-50 dark:bg-gray-500 dark:ring-dark-500"
>
<span className="text-[10px] font-medium leading-none text-white">
{member?.user?.name &&
member.user.name
.split(" ")
.map((namePart) =>
namePart
.charAt(0)
.toUpperCase(),
)
.join("")}
{member?.user?.name
?.split(" ")
.map((namePart) =>
namePart
.charAt(0)
.toUpperCase(),
)
.join("")}
</span>
</span>
))}

View File

@@ -7,7 +7,7 @@ import { useWorkspace } from "~/providers/workspace";
import { Formik, Form, Field } from "formik";
import { NewBoardInput } from "~/types/router.types";
import { type NewBoardInput } from "~/types/router.types";
export function NewBoardForm() {
const utils = api.useUtils();