From cedc884d9259d4970c80bf2ce5b935980d71a04a Mon Sep 17 00:00:00 2001 From: Aaryan Khandelwal Date: Fri, 27 Jan 2023 12:55:20 +0530 Subject: [PATCH 01/15] feat: added user auth --- .../common/board-view/single-issue.tsx | 212 ++++++++++-------- .../common/list-view/single-issue.tsx | 21 +- .../project/confirm-project-deletion.tsx | 12 +- .../project/confirm-project-member-remove.tsx | 4 +- .../project/cycles/board-view/index.tsx | 11 +- .../cycles/board-view/single-board.tsx | 14 +- .../cycles/create-update-cycle-modal.tsx | 12 +- .../project/cycles/list-view/index.tsx | 5 +- .../project/issues/BoardView/index.tsx | 8 +- .../project/issues/BoardView/single-board.tsx | 8 +- .../project/issues/list-view/index.tsx | 7 +- .../project/modules/board-view/index.tsx | 11 +- .../modules/board-view/single-board.tsx | 24 +- .../project/modules/list-view/index.tsx | 5 +- .../project/send-project-invitation-modal.tsx | 77 +++---- .../app/components/ui/custom-select/index.tsx | 14 +- .../workspace/confirm-workspace-deletion.tsx | 13 +- .../confirm-workspace-member-remove.tsx | 4 +- .../send-workspace-invitation-modal.tsx | 4 +- ...leInvitation.tsx => single-invitation.tsx} | 0 .../projects/[projectId]/cycles/[cycleId].tsx | 51 +++-- .../projects/[projectId]/issues/index.tsx | 41 ++-- .../[projectId]/modules/[moduleId].tsx | 59 +++-- .../projects/[projectId]/settings/control.tsx | 23 +- apps/app/pages/invitations/index.tsx | 8 +- apps/app/types/users.d.ts | 7 + 26 files changed, 356 insertions(+), 299 deletions(-) rename apps/app/components/workspace/{SingleInvitation.tsx => single-invitation.tsx} (100%) diff --git a/apps/app/components/common/board-view/single-issue.tsx b/apps/app/components/common/board-view/single-issue.tsx index dc774add5..445982035 100644 --- a/apps/app/components/common/board-view/single-issue.tsx +++ b/apps/app/components/common/board-view/single-issue.tsx @@ -4,7 +4,7 @@ import Link from "next/link"; import Image from "next/image"; import { useRouter } from "next/router"; // swr -import useSWR from "swr"; +import useSWR, { mutate } from "swr"; // react-beautiful-dnd import { DraggableStateSnapshot } from "react-beautiful-dnd"; // headless ui @@ -17,48 +17,49 @@ import issuesService from "services/issues.service"; import stateService from "services/state.service"; import projectService from "services/project.service"; // components -import { AssigneesList } from "components/ui/avatar"; +import { CustomSelect, AssigneesList } from "components/ui"; // helpers import { renderShortNumericDateFormat, findHowManyDaysLeft } from "helpers/date-time.helper"; import { addSpaceIfCamelCase } from "helpers/string.helper"; // types -import { IIssue, IssueResponse, IUserLite, IWorkspaceMember, Properties } from "types"; +import { IIssue, IUserLite, IWorkspaceMember, Properties, UserAuth } from "types"; // common import { PRIORITIES } from "constants/"; -import { PROJECT_ISSUES_LIST, STATE_LIST, PROJECT_DETAILS } from "constants/fetch-keys"; +import { + STATE_LIST, + PROJECT_DETAILS, + CYCLE_ISSUES, + MODULE_ISSUES, + PROJECT_ISSUES_LIST, +} from "constants/fetch-keys"; import { getPriorityIcon } from "constants/global"; type Props = { + type?: string; + typeId?: string; issue: IIssue; properties: Properties; snapshot?: DraggableStateSnapshot; assignees: Partial[] | (Partial | undefined)[]; people: IWorkspaceMember[] | undefined; handleDeleteIssue?: React.Dispatch>; - partialUpdateIssue: any; + userAuth: UserAuth; }; const SingleBoardIssue: React.FC = ({ + type, + typeId, issue, properties, snapshot, assignees, people, handleDeleteIssue, - partialUpdateIssue, + userAuth, }) => { const router = useRouter(); const { workspaceSlug, projectId } = router.query; - const { data: issues } = useSWR( - workspaceSlug && projectId - ? PROJECT_ISSUES_LIST(workspaceSlug as string, projectId as string) - : null, - workspaceSlug && projectId - ? () => issuesService.getIssues(workspaceSlug as string, projectId as string) - : null - ); - const { data: states } = useSWR( workspaceSlug && projectId ? STATE_LIST(projectId as string) : null, workspaceSlug && projectId @@ -73,7 +74,25 @@ const SingleBoardIssue: React.FC = ({ : null ); - const totalChildren = issues?.results.filter((i) => i.parent === issue.id).length; + const partialUpdateIssue = (formData: Partial) => { + if (!workspaceSlug || !projectId) return; + + issuesService + .patchIssue(workspaceSlug as string, projectId as string, issue.id, formData) + .then((res) => { + if (typeId) { + mutate(CYCLE_ISSUES(typeId ?? "")); + mutate(MODULE_ISSUES(typeId ?? "")); + } + + mutate(PROJECT_ISSUES_LIST(workspaceSlug as string, projectId as string)); + }) + .catch((error) => { + console.log(error); + }); + }; + + const isNotAllowed = userAuth.isGuest || userAuth.isViewer; return (
= ({ }`} >
- {handleDeleteIssue && ( + {handleDeleteIssue && !isNotAllowed && (