diff --git a/apps/app/components/project/issues/create-update-issue-modal/select-assignee.tsx b/apps/app/components/project/issues/create-update-issue-modal/select-assignee.tsx
index 1d660bf7b1e..6d4759f2cc7 100644
--- a/apps/app/components/project/issues/create-update-issue-modal/select-assignee.tsx
+++ b/apps/app/components/project/issues/create-update-issue-modal/select-assignee.tsx
@@ -1,12 +1,12 @@
import React from "react";
-// swr
+
+import { useRouter } from "next/router";
+
import useSWR from "swr";
-// react hook form
+
import { Controller } from "react-hook-form";
// service
import projectServices from "lib/services/project.service";
-// hooks
-import useUser from "lib/hooks/useUser";
// fetch keys
import { PROJECT_MEMBERS } from "constants/fetch-keys";
// types
@@ -21,12 +21,13 @@ type Props = {
};
const SelectAssignee: React.FC = ({ control }) => {
- const { activeWorkspace, activeProject } = useUser();
+ const router = useRouter();
+ const { workspaceSlug, projectId } = router.query;
const { data: people } = useSWR(
- activeWorkspace && activeProject ? PROJECT_MEMBERS(activeProject.id) : null,
- activeWorkspace && activeProject
- ? () => projectServices.projectMembers(activeWorkspace.slug, activeProject.id)
+ workspaceSlug && projectId ? PROJECT_MEMBERS(projectId as string) : null,
+ workspaceSlug && projectId
+ ? () => projectServices.projectMembers(workspaceSlug as string, projectId as string)
: null
);
diff --git a/apps/app/components/project/issues/create-update-issue-modal/select-cycle.tsx b/apps/app/components/project/issues/create-update-issue-modal/select-cycle.tsx
index 977a2196766..117a1753d07 100644
--- a/apps/app/components/project/issues/create-update-issue-modal/select-cycle.tsx
+++ b/apps/app/components/project/issues/create-update-issue-modal/select-cycle.tsx
@@ -3,8 +3,6 @@ import React from "react";
import useSWR from "swr";
// react hook form
import { Controller } from "react-hook-form";
-// hooks
-import useUser from "lib/hooks/useUser";
// services
import cycleServices from "lib/services/cycles.service";
// constants
diff --git a/apps/app/components/project/issues/create-update-issue-modal/select-labels.tsx b/apps/app/components/project/issues/create-update-issue-modal/select-labels.tsx
index a4a7579aeb8..731bc59387d 100644
--- a/apps/app/components/project/issues/create-update-issue-modal/select-labels.tsx
+++ b/apps/app/components/project/issues/create-update-issue-modal/select-labels.tsx
@@ -1,13 +1,13 @@
import React, { useEffect, useState } from "react";
-// swr
+
+import { useRouter } from "next/router";
+
import useSWR from "swr";
-// react hook form
+
import { useForm, Controller } from "react-hook-form";
import type { Control } from "react-hook-form";
// services
import issuesServices from "lib/services/issues.service";
-// hooks
-import useUser from "lib/hooks/useUser";
// fetching keys
import { PROJECT_ISSUE_LABELS } from "constants/fetch-keys";
// icons
@@ -28,21 +28,22 @@ const defaultValues: Partial = {
};
const SelectLabels: React.FC = ({ control }) => {
- const { activeWorkspace, activeProject } = useUser();
+ const router = useRouter();
+ const { workspaceSlug, projectId } = router.query;
const [isOpen, setIsOpen] = useState(false);
const { data: issueLabels, mutate: issueLabelsMutate } = useSWR(
- activeProject && activeWorkspace ? PROJECT_ISSUE_LABELS(activeProject.id) : null,
- activeProject && activeWorkspace
- ? () => issuesServices.getIssueLabels(activeWorkspace.slug, activeProject.id)
+ workspaceSlug && projectId ? PROJECT_ISSUE_LABELS(workspaceSlug as string) : null,
+ workspaceSlug && projectId
+ ? () => issuesServices.getIssueLabels(workspaceSlug as string, projectId as string)
: null
);
const onSubmit = async (data: IIssueLabels) => {
- if (!activeProject || !activeWorkspace || isSubmitting) return;
+ if (!projectId || !workspaceSlug || isSubmitting) return;
await issuesServices
- .createIssueLabel(activeWorkspace.slug, activeProject.id, data)
+ .createIssueLabel(workspaceSlug as string, projectId as string, data)
.then((response) => {
issueLabelsMutate((prevData) => [...(prevData ?? []), response], false);
setIsOpen(false);
diff --git a/apps/app/components/project/issues/issue-detail/activity/index.tsx b/apps/app/components/project/issues/issue-detail/activity/index.tsx
index a3acb14dac2..cd1bdc1c77f 100644
--- a/apps/app/components/project/issues/issue-detail/activity/index.tsx
+++ b/apps/app/components/project/issues/issue-detail/activity/index.tsx
@@ -1,13 +1,14 @@
import React from "react";
-// next
-import { useRouter } from "next/router";
+
import Image from "next/image";
+import { useRouter } from "next/router";
+
+import useSWR from "swr";
+
// fetch-keys
import { PROJECT_ISSUES_ACTIVITY, STATE_LIST, PROJECT_ISSUES_LIST } from "constants/fetch-keys";
// common
import { addSpaceIfCamelCase, timeAgo } from "constants/common";
-// swr
-import useSWR from "swr";
// services
import stateService from "lib/services/state.service";
import issuesServices from "lib/services/issues.service";
@@ -38,25 +39,23 @@ const activityIcons: {
const IssueActivitySection: React.FC = () => {
const router = useRouter();
- const { issueId, projectId } = router.query;
-
- const { activeWorkspace, activeProject } = useUser();
+ const { workspaceSlug, projectId, issueId } = router.query;
const { data: issues } = useSWR(
- activeWorkspace && activeProject
- ? PROJECT_ISSUES_LIST(activeWorkspace.slug, activeProject.id)
+ workspaceSlug && projectId
+ ? PROJECT_ISSUES_LIST(workspaceSlug as string, projectId as string)
: null,
- activeWorkspace && activeProject
- ? () => issuesServices.getIssues(activeWorkspace.slug, activeProject.id)
+ workspaceSlug && projectId
+ ? () => issuesServices.getIssues(workspaceSlug as string, projectId as string)
: null
);
const { data: issueActivities } = useSWR(
- activeWorkspace && projectId && issueId ? PROJECT_ISSUES_ACTIVITY : null,
- activeWorkspace && projectId && issueId
+ workspaceSlug && projectId && issueId ? PROJECT_ISSUES_ACTIVITY : null,
+ workspaceSlug && projectId && issueId
? () =>
issuesServices.getIssueActivities(
- activeWorkspace.slug,
+ workspaceSlug as string,
projectId as string,
issueId as string
)
@@ -64,9 +63,9 @@ const IssueActivitySection: React.FC = () => {
);
const { data: states } = useSWR(
- activeWorkspace && activeProject ? STATE_LIST(activeProject.id) : null,
- activeWorkspace && activeProject
- ? () => stateService.getStates(activeWorkspace.slug, activeProject.id)
+ workspaceSlug && projectId ? STATE_LIST(projectId as string) : null,
+ workspaceSlug && projectId
+ ? () => stateService.getStates(workspaceSlug as string, projectId as string)
: null
);
diff --git a/apps/app/components/project/issues/issue-detail/add-as-sub-issue.tsx b/apps/app/components/project/issues/issue-detail/add-as-sub-issue.tsx
index 66813bfb85d..737e1bd22fe 100644
--- a/apps/app/components/project/issues/issue-detail/add-as-sub-issue.tsx
+++ b/apps/app/components/project/issues/issue-detail/add-as-sub-issue.tsx
@@ -1,8 +1,9 @@
-// react
import React, { useState } from "react";
-// swr
+
+import { useRouter } from "next/router";
+
import useSWR, { mutate } from "swr";
-// headless ui
+
import { Combobox, Dialog, Transition } from "@headlessui/react";
// services
import issuesServices from "lib/services/issues.service";
@@ -26,14 +27,15 @@ type Props = {
const AddAsSubIssue: React.FC = ({ isOpen, setIsOpen, parent }) => {
const [query, setQuery] = useState("");
- const { activeWorkspace, activeProject } = useUser();
+ const router = useRouter();
+ const { workspaceSlug, projectId } = router.query;
const { data: issues } = useSWR(
- activeWorkspace && activeProject
- ? PROJECT_ISSUES_LIST(activeWorkspace.slug, activeProject.id)
+ workspaceSlug && projectId
+ ? PROJECT_ISSUES_LIST(workspaceSlug as string, projectId as string)
: null,
- activeWorkspace && activeProject
- ? () => issuesServices.getIssues(activeWorkspace.slug, activeProject.id)
+ workspaceSlug && projectId
+ ? () => issuesServices.getIssues(workspaceSlug as string, projectId as string)
: null
);
@@ -49,12 +51,12 @@ const AddAsSubIssue: React.FC = ({ isOpen, setIsOpen, parent }) => {
};
const addAsSubIssue = (issueId: string) => {
- if (activeWorkspace && activeProject) {
+ if (workspaceSlug && projectId) {
issuesServices
- .patchIssue(activeWorkspace.slug, activeProject.id, issueId, { parent: parent?.id })
+ .patchIssue(workspaceSlug as string, projectId as string, issueId, { parent: parent?.id })
.then((res) => {
mutate(
- PROJECT_ISSUES_LIST(activeWorkspace.slug, activeProject.id),
+ PROJECT_ISSUES_LIST(workspaceSlug as string, projectId as string),
(prevData) => ({
...(prevData as IssueResponse),
results: (prevData?.results ?? []).map((p) =>
diff --git a/apps/app/components/project/issues/issue-detail/comment/issue-comment-section.tsx b/apps/app/components/project/issues/issue-detail/comment/issue-comment-section.tsx
index 78497b25d01..4335d0cd00c 100644
--- a/apps/app/components/project/issues/issue-detail/comment/issue-comment-section.tsx
+++ b/apps/app/components/project/issues/issue-detail/comment/issue-comment-section.tsx
@@ -34,16 +34,14 @@ const IssueCommentSection: React.FC = () => {
const router = useRouter();
- let { issueId, projectId } = router.query;
-
- const { activeWorkspace } = useUser();
+ let { workspaceSlug, projectId, issueId } = router.query;
const { data: comments, mutate } = useSWR(
- activeWorkspace && projectId && issueId ? PROJECT_ISSUES_COMMENTS(issueId as string) : null,
- activeWorkspace && projectId && issueId
+ workspaceSlug && projectId && issueId ? PROJECT_ISSUES_COMMENTS(issueId as string) : null,
+ workspaceSlug && projectId && issueId
? () =>
issuesServices.getIssueComments(
- activeWorkspace.slug,
+ workspaceSlug as string,
projectId as string,
issueId as string
)
@@ -51,9 +49,9 @@ const IssueCommentSection: React.FC = () => {
);
const onSubmit = async (formData: IIssueComment) => {
- if (!activeWorkspace || !projectId || !issueId || isSubmitting) return;
+ if (!workspaceSlug || !projectId || !issueId || isSubmitting) return;
await issuesServices
- .createIssueComment(activeWorkspace.slug, projectId as string, issueId as string, formData)
+ .createIssueComment(workspaceSlug as string, projectId as string, issueId as string, formData)
.then((response) => {
console.log(response);
mutate((prevData) => [response, ...(prevData ?? [])]);
@@ -65,10 +63,10 @@ const IssueCommentSection: React.FC = () => {
};
const onCommentUpdate = async (comment: IIssueComment) => {
- if (!activeWorkspace || !projectId || !issueId || isSubmitting) return;
+ if (!workspaceSlug || !projectId || !issueId || isSubmitting) return;
await issuesServices
.patchIssueComment(
- activeWorkspace.slug,
+ workspaceSlug as string,
projectId as string,
issueId as string,
comment.id,
@@ -88,9 +86,14 @@ const IssueCommentSection: React.FC = () => {
};
const onCommentDelete = async (commentId: string) => {
- if (!activeWorkspace || !projectId || !issueId || isSubmitting) return;
+ if (!workspaceSlug || !projectId || !issueId || isSubmitting) return;
await issuesServices
- .deleteIssueComment(activeWorkspace.slug, projectId as string, issueId as string, commentId)
+ .deleteIssueComment(
+ workspaceSlug as string,
+ projectId as string,
+ issueId as string,
+ commentId
+ )
.then((response) => {
mutate((prevData) => (prevData ?? []).filter((c) => c.id !== commentId));
console.log(response);
diff --git a/apps/app/components/project/issues/issue-detail/issue-detail-sidebar/index.tsx b/apps/app/components/project/issues/issue-detail/issue-detail-sidebar/index.tsx
index efabb6888b6..f048e71d894 100644
--- a/apps/app/components/project/issues/issue-detail/issue-detail-sidebar/index.tsx
+++ b/apps/app/components/project/issues/issue-detail/issue-detail-sidebar/index.tsx
@@ -10,7 +10,6 @@ import { TwitterPicker } from "react-color";
// services
import issuesServices from "lib/services/issues.service";
// hooks
-import useUser from "lib/hooks/useUser";
import useToast from "lib/hooks/useToast";
// components
import ConfirmIssueDeletion from "components/project/issues/confirm-issue-deletion";
@@ -39,7 +38,7 @@ import {
import type { Control } from "react-hook-form";
import type { ICycle, IIssue, IIssueLabels } from "types";
// fetch-keys
-import { PROJECT_ISSUE_LABELS, PROJECT_ISSUES_LIST } from "constants/fetch-keys";
+import { PROJECT_ISSUE_LABELS, PROJECT_ISSUES_LIST, PROJECT_DETAILS } from "constants/fetch-keys";
// common
import { copyTextToClipboard } from "constants/common";
@@ -62,35 +61,29 @@ const IssueDetailSidebar: React.FC = ({
watch: watchIssue,
}) => {
const [createLabelForm, setCreateLabelForm] = useState(false);
-
- const { activeWorkspace, activeProject } = useUser();
+ const [deleteIssueModal, setDeleteIssueModal] = useState(false);
const router = useRouter();
-
- const {
- query: { workspaceSlug },
- } = router;
+ const { workspaceSlug, projectId } = router.query;
const { setToastAlert } = useToast();
const { data: issues } = useSWR(
- activeWorkspace && activeProject
- ? PROJECT_ISSUES_LIST(activeWorkspace.slug, activeProject.id)
+ workspaceSlug && projectId
+ ? PROJECT_ISSUES_LIST(workspaceSlug as string, projectId as string)
: null,
- activeWorkspace && activeProject
- ? () => issuesServices.getIssues(activeWorkspace.slug, activeProject.id)
+ workspaceSlug && projectId
+ ? () => issuesServices.getIssues(workspaceSlug as string, projectId as string)
: null
);
const { data: issueLabels, mutate: issueLabelMutate } = useSWR(
- activeProject && activeWorkspace ? PROJECT_ISSUE_LABELS(activeProject.id) : null,
- activeProject && activeWorkspace
- ? () => issuesServices.getIssueLabels(activeWorkspace.slug, activeProject.id)
+ workspaceSlug && projectId ? PROJECT_ISSUE_LABELS(projectId as string) : null,
+ workspaceSlug && projectId
+ ? () => issuesServices.getIssueLabels(workspaceSlug as string, projectId as string)
: null
);
- const [deleteIssueModal, setDeleteIssueModal] = useState(false);
-
const {
register,
handleSubmit,
@@ -103,9 +96,9 @@ const IssueDetailSidebar: React.FC = ({
});
const handleNewLabel = (formData: any) => {
- if (!activeWorkspace || !activeProject || isSubmitting) return;
+ if (!workspaceSlug || !projectId || isSubmitting) return;
issuesServices
- .createIssueLabel(activeWorkspace.slug, activeProject.id, formData)
+ .createIssueLabel(workspaceSlug as string, projectId as string, formData)
.then((res) => {
console.log(res);
reset(defaultValues);
@@ -116,11 +109,11 @@ const IssueDetailSidebar: React.FC = ({
};
const handleCycleChange = (cycleDetail: ICycle) => {
- if (!activeWorkspace || !activeProject || !issueDetail) return;
+ if (!workspaceSlug || !projectId || !issueDetail) return;
submitChanges({ cycle: cycleDetail.id, cycle_detail: cycleDetail });
issuesServices
- .addIssueToCycle(activeWorkspace.slug, activeProject.id, cycleDetail.id, {
+ .addIssueToCycle(workspaceSlug as string, projectId as string, cycleDetail.id, {
issues: [issueDetail.id],
})
.then(() => {
@@ -138,7 +131,7 @@ const IssueDetailSidebar: React.FC = ({
- {activeProject?.identifier}-{issueDetail?.sequence_id}
+ {issueDetail?.project_detail?.identifier}-{issueDetail?.sequence_id}
= ({
className="rounded-md border p-2 shadow-sm duration-300 hover:bg-gray-100 focus:border-indigo-500 focus:outline-none focus:ring-1 focus:ring-indigo-500"
onClick={() =>
copyTextToClipboard(
- `https://app.plane.so/${workspaceSlug}/projects/${activeProject?.id}/issues/${issueDetail?.id}`
+ `https://app.plane.so/${workspaceSlug}/projects/${issueDetail?.project_detail?.id}/issues/${issueDetail?.id}`
)
.then(() => {
setToastAlert({
diff --git a/apps/app/components/project/issues/issue-detail/issue-detail-sidebar/select-assignee.tsx b/apps/app/components/project/issues/issue-detail/issue-detail-sidebar/select-assignee.tsx
index 495cdf8de53..b7c873a8f4d 100644
--- a/apps/app/components/project/issues/issue-detail/issue-detail-sidebar/select-assignee.tsx
+++ b/apps/app/components/project/issues/issue-detail/issue-detail-sidebar/select-assignee.tsx
@@ -1,10 +1,10 @@
-// react
import React from "react";
-// next
+
import Image from "next/image";
-// swr
+import { useRouter } from "next/router";
+
import useSWR from "swr";
-// react-hook-form
+
import { Control, Controller } from "react-hook-form";
// services
import workspaceService from "lib/services/workspace.service";
@@ -29,17 +29,18 @@ type Props = {
};
const SelectAssignee: React.FC = ({ control, submitChanges }) => {
- const { activeWorkspace } = useUser();
+ const router = useRouter();
+ const { workspaceSlug } = router.query;
const { data: people } = useSWR(
- activeWorkspace ? WORKSPACE_MEMBERS(activeWorkspace.slug) : null,
- activeWorkspace ? () => workspaceService.workspaceMembers(activeWorkspace.slug) : null
+ workspaceSlug ? WORKSPACE_MEMBERS(workspaceSlug as string) : null,
+ workspaceSlug ? () => workspaceService.workspaceMembers(workspaceSlug as string) : null
);
return (
-
+
@@ -58,14 +59,14 @@ const SelectAssignee: React.FC
= ({ control, submitChanges }) => {
>
{({ open }) => (
-
+
-
+
{value && Array.isArray(value) ? (
<>
{value.length > 0 ? (
@@ -82,7 +83,7 @@ const SelectAssignee: React.FC
= ({ control, submitChanges }) => {
}`}
>
{person && person.avatar && person.avatar !== "" ? (
-
+
= ({ control, submitChanges }) => {
) : (
{person?.first_name.charAt(0)}
@@ -102,7 +103,7 @@ const SelectAssignee: React.FC
= ({ control, submitChanges }) => {
);
})
) : (
-
+
= ({ control, submitChanges }) => {
leaveFrom="transform opacity-100 scale-100"
leaveTo="transform opacity-0 scale-95"
>
-
+
{people ? (
people.length > 0 ? (
@@ -138,7 +139,7 @@ const SelectAssignee: React.FC
= ({ control, submitChanges }) => {
className={({ active, selected }) =>
`${
active || selected ? "bg-indigo-50" : ""
- } flex items-center gap-2 text-gray-900 cursor-pointer select-none p-2 truncate`
+ } flex cursor-pointer select-none items-center gap-2 truncate p-2 text-gray-900`
}
value={option.member.id}
>
@@ -153,7 +154,7 @@ const SelectAssignee: React.FC = ({ control, submitChanges }) => {
/>
) : (
-
+
{option.member.first_name && option.member.first_name !== ""
? option.member.first_name.charAt(0)
: option.member.email.charAt(0)}
diff --git a/apps/app/components/project/issues/issue-detail/issue-detail-sidebar/select-blocked.tsx b/apps/app/components/project/issues/issue-detail/issue-detail-sidebar/select-blocked.tsx
index 06366a3f69c..53bcf3a18cb 100644
--- a/apps/app/components/project/issues/issue-detail/issue-detail-sidebar/select-blocked.tsx
+++ b/apps/app/components/project/issues/issue-detail/issue-detail-sidebar/select-blocked.tsx
@@ -1,18 +1,16 @@
-// react
import React, { useState } from "react";
-// next
+
import Link from "next/link";
import { useRouter } from "next/router";
-// swr
+
import useSWR from "swr";
-// react-hook-form
+
import { SubmitHandler, useForm, UseFormWatch } from "react-hook-form";
// services
import issuesService from "lib/services/issues.service";
// constants
import { PROJECT_ISSUES_LIST } from "constants/fetch-keys";
// hooks
-import useUser from "lib/hooks/useUser";
import useToast from "lib/hooks/useToast";
// headless ui
import { Combobox, Dialog, Transition } from "@headlessui/react";
@@ -37,28 +35,27 @@ type Props = {
watch: UseFormWatch
;
};
-const SelectBlocked: React.FC = ({ submitChanges, issueDetail, issuesList, watch }) => {
+const SelectBlocked: React.FC = ({ submitChanges, issuesList, watch }) => {
const [query, setQuery] = useState("");
const [isBlockedModalOpen, setIsBlockedModalOpen] = useState(false);
const router = useRouter();
const {
- query: { workspaceSlug },
+ query: { workspaceSlug, projectId },
} = router;
- const { activeWorkspace, activeProject } = useUser();
const { setToastAlert } = useToast();
- const { data: issues, mutate: mutateIssues } = useSWR(
- activeWorkspace && activeProject
- ? PROJECT_ISSUES_LIST(activeWorkspace.slug, activeProject.id)
+ const { data: issues } = useSWR(
+ workspaceSlug && projectId
+ ? PROJECT_ISSUES_LIST(workspaceSlug as string, projectId as string)
: null,
- activeWorkspace && activeProject
- ? () => issuesService.getIssues(activeWorkspace.slug, activeProject.id)
+ workspaceSlug && projectId
+ ? () => issuesService.getIssues(workspaceSlug as string, projectId as string)
: null
);
- const { register, handleSubmit, reset, watch: watchIssues } = useForm();
+ const { register, handleSubmit, reset } = useForm();
const handleClose = () => {
setIsBlockedModalOpen(false);
@@ -105,15 +102,15 @@ const SelectBlocked: React.FC = ({ submitChanges, issueDetail, issuesList
}}
>
i.id === issue)?.id
}`}
>
- {`${activeProject?.identifier}-${
- issues?.results.find((i) => i.id === issue)?.sequence_id
- }`}
+ {`${
+ issues?.results.find((i) => i.id === issue)?.project_detail?.identifier
+ }-${issues?.results.find((i) => i.id === issue)?.sequence_id}`}
@@ -201,28 +198,28 @@ const SelectBlocked: React.FC = ({ submitChanges, issueDetail, issuesList
)
}
>
- {({ active }) => (
- <>
-
-
-
-
- {activeProject?.identifier}-{issue.sequence_id}
-
- {issue.name}
-
- >
- )}
+
+
+
+
+ {
+ issues?.results.find((i) => i.id === issue.id)
+ ?.project_detail?.identifier
+ }
+ -{issue.sequence_id}
+
+ {issue.name}
+
);
}
diff --git a/apps/app/components/project/issues/issue-detail/issue-detail-sidebar/select-blocker.tsx b/apps/app/components/project/issues/issue-detail/issue-detail-sidebar/select-blocker.tsx
index 31865828e0a..cf00e8d2fef 100644
--- a/apps/app/components/project/issues/issue-detail/issue-detail-sidebar/select-blocker.tsx
+++ b/apps/app/components/project/issues/issue-detail/issue-detail-sidebar/select-blocker.tsx
@@ -1,18 +1,17 @@
-// react
import React, { useState } from "react";
-// next
+
import Link from "next/link";
import { useRouter } from "next/router";
-// swr
+
import useSWR from "swr";
-// react-hook-form
+
import { SubmitHandler, useForm, UseFormWatch } from "react-hook-form";
// constants
-import { PROJECT_ISSUES_LIST } from "constants/fetch-keys";
+import { PROJECT_ISSUES_LIST, PROJECT_DETAILS } from "constants/fetch-keys";
// services
import issuesServices from "lib/services/issues.service";
+import projectService from "lib/services/project.service";
// hooks
-import useUser from "lib/hooks/useUser";
import useToast from "lib/hooks/useToast";
// headless ui
import { Combobox, Dialog, Transition } from "@headlessui/react";
@@ -40,20 +39,26 @@ const SelectBlocker: React.FC = ({ submitChanges, issuesList, watch }) =>
const [query, setQuery] = useState("");
const [isBlockerModalOpen, setIsBlockerModalOpen] = useState(false);
- const { activeProject, activeWorkspace } = useUser();
const { setToastAlert } = useToast();
const router = useRouter();
const {
- query: { workspaceSlug },
+ query: { projectId, workspaceSlug },
} = router;
const { data: issues } = useSWR(
- activeWorkspace && activeProject
- ? PROJECT_ISSUES_LIST(activeWorkspace.slug, activeProject.id)
+ workspaceSlug && projectId
+ ? PROJECT_ISSUES_LIST(workspaceSlug as string, projectId as string)
: null,
- activeWorkspace && activeProject
- ? () => issuesServices.getIssues(activeWorkspace.slug, activeProject.id)
+ workspaceSlug && projectId
+ ? () => issuesServices.getIssues(workspaceSlug as string, projectId as string)
+ : null
+ );
+
+ const { data: projectDetails } = useSWR(
+ workspaceSlug && projectId ? PROJECT_DETAILS(projectId as string) : null,
+ workspaceSlug && projectId
+ ? () => projectService.getProject(workspaceSlug as string, projectId as string)
: null
);
@@ -96,13 +101,13 @@ const SelectBlocker: React.FC = ({ submitChanges, issuesList, watch }) =>
className="group flex cursor-pointer items-center gap-1 rounded-2xl border border-white px-1.5 py-0.5 text-xs text-yellow-500 duration-300 hover:border-yellow-500 hover:bg-yellow-50"
>
i.id === issue)?.id
}`}
>
- {`${activeProject?.identifier}-${
+ {`${projectDetails?.identifier}-${
issues?.results.find((i) => i.id === issue)?.sequence_id
}`}
@@ -218,7 +223,7 @@ const SelectBlocker: React.FC = ({ submitChanges, issuesList, watch }) =>
}}
/>
- {activeProject?.identifier}-{issue.sequence_id}
+ {projectDetails?.identifier}-{issue.sequence_id}
{issue.name}
diff --git a/apps/app/components/project/issues/issue-detail/issue-detail-sidebar/select-cycle.tsx b/apps/app/components/project/issues/issue-detail/issue-detail-sidebar/select-cycle.tsx
index 56465a0a3ae..74956f83557 100644
--- a/apps/app/components/project/issues/issue-detail/issue-detail-sidebar/select-cycle.tsx
+++ b/apps/app/components/project/issues/issue-detail/issue-detail-sidebar/select-cycle.tsx
@@ -1,7 +1,9 @@
import React from "react";
-// swr
+
+import { useRouter } from "next/router";
+
import useSWR, { mutate } from "swr";
-// react-hook-form
+
import { Control, Controller, UseFormWatch } from "react-hook-form";
// hooks
import useUser from "lib/hooks/useUser";
@@ -26,21 +28,22 @@ type Props = {
watch: UseFormWatch
;
};
-const SelectCycle: React.FC = ({ issueDetail, control, handleCycleChange, watch }) => {
- const { activeWorkspace, activeProject } = useUser();
+const SelectCycle: React.FC = ({ issueDetail, control, handleCycleChange }) => {
+ const router = useRouter();
+ const { workspaceSlug, projectId } = router.query;
const { data: cycles } = useSWR(
- activeWorkspace && activeProject ? CYCLE_LIST(activeProject.id) : null,
- activeWorkspace && activeProject
- ? () => cyclesService.getCycles(activeWorkspace.slug, activeProject.id)
+ workspaceSlug && projectId ? CYCLE_LIST(projectId as string) : null,
+ workspaceSlug && projectId
+ ? () => cyclesService.getCycles(workspaceSlug as string, projectId as string)
: null
);
const removeIssueFromCycle = (bridgeId: string, cycleId: string) => {
- if (!activeWorkspace || !activeProject) return;
+ if (!workspaceSlug || !projectId) return;
issuesService
- .removeIssueFromCycle(activeWorkspace.slug, activeProject.id, cycleId, bridgeId)
+ .removeIssueFromCycle(workspaceSlug as string, projectId as string, cycleId, bridgeId)
.then((res) => {
console.log(res);
mutate(
@@ -50,8 +53,8 @@ const SelectCycle: React.FC = ({ issueDetail, control, handleCycleChange,
);
mutate(
- activeWorkspace && activeProject
- ? PROJECT_ISSUES_LIST(activeWorkspace.slug, activeProject.id)
+ workspaceSlug && projectId
+ ? PROJECT_ISSUES_LIST(workspaceSlug as string, projectId as string)
: null
);
})
diff --git a/apps/app/components/project/issues/issue-detail/issue-detail-sidebar/select-module.tsx b/apps/app/components/project/issues/issue-detail/issue-detail-sidebar/select-module.tsx
index ce00754286d..01bfeda2e01 100644
--- a/apps/app/components/project/issues/issue-detail/issue-detail-sidebar/select-module.tsx
+++ b/apps/app/components/project/issues/issue-detail/issue-detail-sidebar/select-module.tsx
@@ -1,10 +1,10 @@
import React from "react";
-// swr
+
+import { useRouter } from "next/router";
+
import useSWR from "swr";
-// react-hook-form
+
import { Control, Controller } from "react-hook-form";
-// hooks
-import useUser from "lib/hooks/useUser";
// constants
import { MODULE_LIST } from "constants/fetch-keys";
// services
@@ -24,12 +24,13 @@ type Props = {
};
const SelectModule: React.FC = ({ control, handleModuleChange }) => {
- const { activeWorkspace, activeProject } = useUser();
+ const router = useRouter();
+ const { workspaceSlug, projectId } = router.query;
const { data: modules } = useSWR(
- activeWorkspace && activeProject ? MODULE_LIST(activeProject.id) : null,
- activeWorkspace && activeProject
- ? () => modulesService.getModules(activeWorkspace.slug, activeProject.id)
+ workspaceSlug && projectId ? MODULE_LIST(projectId as string) : null,
+ workspaceSlug && projectId
+ ? () => modulesService.getModules(workspaceSlug as string, projectId as string)
: null
);
diff --git a/apps/app/components/project/issues/issue-detail/issue-detail-sidebar/select-parent.tsx b/apps/app/components/project/issues/issue-detail/issue-detail-sidebar/select-parent.tsx
index bb9afc02ad8..ce001ec3843 100644
--- a/apps/app/components/project/issues/issue-detail/issue-detail-sidebar/select-parent.tsx
+++ b/apps/app/components/project/issues/issue-detail/issue-detail-sidebar/select-parent.tsx
@@ -1,15 +1,14 @@
-// react
import React, { useState } from "react";
-// swr
+
+import { useRouter } from "next/router";
+
import useSWR from "swr";
-// react-hook-form
+
import { Control, Controller, UseFormWatch } from "react-hook-form";
// fetch keys
import { PROJECT_ISSUES_LIST } from "constants/fetch-keys";
// services
import issuesServices from "lib/services/issues.service";
-// hooks
-import useUser from "lib/hooks/useUser";
// components
import IssuesListModal from "components/project/issues/issues-list-modal";
// icons
@@ -34,14 +33,15 @@ const SelectParent: React.FC = ({
}) => {
const [isParentModalOpen, setIsParentModalOpen] = useState(false);
- const { activeProject, activeWorkspace } = useUser();
+ const router = useRouter();
+ const { workspaceSlug, projectId } = router.query;
const { data: issues } = useSWR(
- activeWorkspace && activeProject
- ? PROJECT_ISSUES_LIST(activeWorkspace.slug, activeProject.id)
+ workspaceSlug && projectId
+ ? PROJECT_ISSUES_LIST(workspaceSlug as string, projectId as string)
: null,
- activeWorkspace && activeProject
- ? () => issuesServices.getIssues(activeWorkspace.slug, activeProject.id)
+ workspaceSlug && projectId
+ ? () => issuesServices.getIssues(workspaceSlug as string, projectId as string)
: null
);
@@ -76,9 +76,9 @@ const SelectParent: React.FC = ({
onClick={() => setIsParentModalOpen(true)}
>
{watch("parent") && watch("parent") !== ""
- ? `${activeProject?.identifier}-${
- issues?.results.find((i) => i.id === watch("parent"))?.sequence_id
- }`
+ ? `${
+ issues?.results.find((i) => i.id === watch("parent"))?.project_detail?.identifier
+ }-${issues?.results.find((i) => i.id === watch("parent"))?.sequence_id}`
: "Select issue"}
diff --git a/apps/app/components/project/issues/issue-detail/issue-detail-sidebar/select-state.tsx b/apps/app/components/project/issues/issue-detail/issue-detail-sidebar/select-state.tsx
index 73813948013..251e10ad94e 100644
--- a/apps/app/components/project/issues/issue-detail/issue-detail-sidebar/select-state.tsx
+++ b/apps/app/components/project/issues/issue-detail/issue-detail-sidebar/select-state.tsx
@@ -1,14 +1,14 @@
import React from "react";
-// swr
+
+import { useRouter } from "next/router";
+
import useSWR from "swr";
-// react-hook-form
+
import { Control, Controller } from "react-hook-form";
// services
import stateService from "lib/services/state.service";
// icons
import { Squares2X2Icon } from "@heroicons/react/24/outline";
-// hooks
-import useUser from "lib/hooks/useUser";
// constants
import { classNames } from "constants/common";
import { STATE_LIST } from "constants/fetch-keys";
@@ -23,12 +23,13 @@ type Props = {
};
const SelectState: React.FC = ({ control, submitChanges }) => {
- const { activeWorkspace, activeProject } = useUser();
+ const router = useRouter();
+ const { workspaceSlug, projectId } = router.query;
const { data: states } = useSWR(
- activeWorkspace && activeProject ? STATE_LIST(activeProject.id) : null,
- activeWorkspace && activeProject
- ? () => stateService.getStates(activeWorkspace.slug, activeProject.id)
+ workspaceSlug && projectId ? STATE_LIST(projectId as string) : null,
+ workspaceSlug && projectId
+ ? () => stateService.getStates(workspaceSlug as string, projectId as string)
: null
);
diff --git a/apps/app/components/project/issues/issues-list-modal.tsx b/apps/app/components/project/issues/issues-list-modal.tsx
index b158aab3b6f..6dbfab48762 100644
--- a/apps/app/components/project/issues/issues-list-modal.tsx
+++ b/apps/app/components/project/issues/issues-list-modal.tsx
@@ -1,15 +1,14 @@
-// react
import React, { useState } from "react";
-// headless ui
+
import { Combobox, Dialog, Transition } from "@headlessui/react";
// ui
import { Button } from "ui";
// icons
import { MagnifyingGlassIcon, RectangleStackIcon } from "@heroicons/react/24/outline";
+// constants
+import { classNames } from "constants/common";
// types
import { IIssue } from "types";
-import { classNames } from "constants/common";
-import useUser from "lib/hooks/useUser";
type Props = {
isOpen: boolean;
@@ -35,8 +34,6 @@ const IssuesListModal: React.FC = ({
const [query, setQuery] = useState("");
const [values, setValues] = useState([]);
- const { activeProject } = useUser();
-
const handleClose = () => {
onClose();
setQuery("");
@@ -77,21 +74,14 @@ const IssuesListModal: React.FC = ({
{multiple ? (
<>
- {
- // setValues(val);
- console.log(val);
- }}
- multiple
- >
+ {}} multiple>
)}
-
+
Cancel
@@ -172,7 +162,7 @@ const IssuesListModal: React.FC
= ({
aria-hidden="true"
/>
setQuery(e.target.value)}
displayValue={() => ""}
@@ -197,26 +187,24 @@ const IssuesListModal: React.FC = ({
value={issue.id}
className={({ active }) =>
classNames(
- "flex items-center gap-2 cursor-pointer select-none rounded-md px-3 py-2",
+ "flex cursor-pointer select-none items-center gap-2 rounded-md px-3 py-2",
active ? "bg-gray-900 bg-opacity-5 text-gray-900" : ""
)
}
onClick={() => handleClose()}
>
- {({ selected }) => (
- <>
-
-
- {activeProject?.identifier}-{issue.sequence_id}
- {" "}
- {issue.name}
- >
- )}
+ <>
+
+
+ {issue.project_detail?.identifier}-{issue.sequence_id}
+ {" "}
+ {issue.name}
+ >
))}
diff --git a/apps/app/components/project/issues/my-issues/ChangeStateDropdown.tsx b/apps/app/components/project/issues/my-issues/ChangeStateDropdown.tsx
index 9e90c0e8da3..5eb248aee1f 100644
--- a/apps/app/components/project/issues/my-issues/ChangeStateDropdown.tsx
+++ b/apps/app/components/project/issues/my-issues/ChangeStateDropdown.tsx
@@ -1,6 +1,7 @@
-// react
import React from "react";
-// swr
+
+import { useRouter } from "next/router";
+
import useSWR from "swr";
// hooks
import useUser from "lib/hooks/useUser";
@@ -25,11 +26,12 @@ type Props = {
};
const ChangeStateDropdown: React.FC = ({ issue, updateIssues }) => {
- const { activeWorkspace } = useUser();
+ const router = useRouter();
+ const { workspaceSlug } = router.query;
const { data: states } = useSWR(
- activeWorkspace ? STATE_LIST(issue.project) : null,
- activeWorkspace ? () => stateServices.getStates(activeWorkspace.slug, issue.project) : null
+ workspaceSlug ? STATE_LIST(issue.project) : null,
+ workspaceSlug ? () => stateServices.getStates(workspaceSlug as string, issue.project) : null
);
return (
@@ -38,8 +40,8 @@ const ChangeStateDropdown: React.FC = ({ issue, updateIssues }) => {
as="div"
value={issue.state}
onChange={(data: string) => {
- if (!activeWorkspace) return;
- updateIssues(activeWorkspace.slug, issue.project, issue.id, {
+ if (!workspaceSlug) return;
+ updateIssues(workspaceSlug as string, issue.project, issue.id, {
state: data,
state_detail: states?.find((state) => state.id === data),
});
@@ -50,7 +52,7 @@ const ChangeStateDropdown: React.FC = ({ issue, updateIssues }) => {
<>
= ({ issue, updateIssues }) => {
{addSpaceIfCamelCase(issue.state_detail.name)}
@@ -73,7 +75,7 @@ const ChangeStateDropdown: React.FC = ({ issue, updateIssues }) => {
leaveFrom="opacity-100"
leaveTo="opacity-0"
>
-
+
{states?.map((state) => (
= ({ isOpen, setIsOpen, data }) => {
const [isDeleteLoading, setIsDeleteLoading] = useState(false);
- const { activeWorkspace } = useUser();
-
const router = useRouter();
const {
query: { workspaceSlug },
@@ -45,9 +41,9 @@ const ConfirmModuleDeletion: React.FC = ({ isOpen, setIsOpen, data }) =>
const handleDeletion = async () => {
setIsDeleteLoading(true);
- if (!activeWorkspace || !data) return;
+ if (!workspaceSlug || !data) return;
await modulesService
- .deleteModule(activeWorkspace.slug, data.project, data.id)
+ .deleteModule(workspaceSlug as string, data.project, data.id)
.then(() => {
mutate(MODULE_LIST(data.project));
router.push(`/${workspaceSlug}/projects/${data.project}/modules`);
diff --git a/apps/app/components/project/modules/create-update-module-modal/index.tsx b/apps/app/components/project/modules/create-update-module-modal/index.tsx
index 91b56fd3ae2..7fb0103ccca 100644
--- a/apps/app/components/project/modules/create-update-module-modal/index.tsx
+++ b/apps/app/components/project/modules/create-update-module-modal/index.tsx
@@ -1,9 +1,11 @@
import React, { useEffect } from "react";
-// swr
+
+import { useRouter } from "next/router";
+
import { mutate } from "swr";
-// react hook form
+
import { useForm } from "react-hook-form";
-// headless
+
import { Dialog, Transition } from "@headlessui/react";
// ui
import { Button, Input, TextArea, Select } from "ui";
@@ -37,15 +39,8 @@ const defaultValues: Partial = {
};
const CreateUpdateModuleModal: React.FC = ({ isOpen, setIsOpen, data, projectId }) => {
- const handleClose = () => {
- setIsOpen(false);
- const timeout = setTimeout(() => {
- reset(defaultValues);
- clearTimeout(timeout);
- }, 500);
- };
-
- const { activeWorkspace } = useUser();
+ const router = useRouter();
+ const { workspaceSlug } = router.query;
const {
register,
@@ -58,8 +53,17 @@ const CreateUpdateModuleModal: React.FC = ({ isOpen, setIsOpen, data, pro
defaultValues,
});
+ useEffect(() => {
+ if (data) {
+ setIsOpen(true);
+ reset(data);
+ } else {
+ reset(defaultValues);
+ }
+ }, [data, setIsOpen, reset]);
+
const onSubmit = async (formData: IModule) => {
- if (!activeWorkspace) return;
+ if (!workspaceSlug) return;
const payload = {
...formData,
start_date: formData.start_date ? renderDateFormat(formData.start_date) : null,
@@ -67,7 +71,7 @@ const CreateUpdateModuleModal: React.FC = ({ isOpen, setIsOpen, data, pro
};
if (!data) {
await modulesService
- .createModule(activeWorkspace.slug, projectId, payload)
+ .createModule(workspaceSlug as string, projectId, payload)
.then((res) => {
mutate(
MODULE_LIST(projectId),
@@ -85,7 +89,7 @@ const CreateUpdateModuleModal: React.FC = ({ isOpen, setIsOpen, data, pro
});
} else {
await modulesService
- .updateModule(activeWorkspace.slug, projectId, data.id, payload)
+ .updateModule(workspaceSlug as string, projectId, data.id, payload)
.then((res) => {
mutate(
MODULE_LIST(projectId),
@@ -112,14 +116,13 @@ const CreateUpdateModuleModal: React.FC = ({ isOpen, setIsOpen, data, pro
}
};
- useEffect(() => {
- if (data) {
- setIsOpen(true);
- reset(data);
- } else {
+ const handleClose = () => {
+ setIsOpen(false);
+ const timeout = setTimeout(() => {
reset(defaultValues);
- }
- }, [data, setIsOpen, reset]);
+ clearTimeout(timeout);
+ }, 500);
+ };
return (
@@ -203,7 +206,7 @@ const CreateUpdateModuleModal: React.FC = ({ isOpen, setIsOpen, data, pro
/>
-
+
diff --git a/apps/app/components/project/modules/create-update-module-modal/select-lead.tsx b/apps/app/components/project/modules/create-update-module-modal/select-lead.tsx
index 2564eabbc28..7bfa815e834 100644
--- a/apps/app/components/project/modules/create-update-module-modal/select-lead.tsx
+++ b/apps/app/components/project/modules/create-update-module-modal/select-lead.tsx
@@ -1,14 +1,13 @@
-// react
import React from "react";
-// swr
+
+import { useRouter } from "next/router";
+
import useSWR from "swr";
-// react hook form
+
import { Controller } from "react-hook-form";
import type { Control } from "react-hook-form";
// service
import projectServices from "lib/services/project.service";
-// hooks
-import useUser from "lib/hooks/useUser";
// ui
import { SearchListbox } from "ui";
// icons
@@ -23,12 +22,13 @@ type Props = {
};
const SelectLead: React.FC
= ({ control }) => {
- const { activeWorkspace, activeProject } = useUser();
+ const router = useRouter();
+ const { workspaceSlug, projectId } = router.query;
const { data: people } = useSWR(
- activeWorkspace && activeProject ? PROJECT_MEMBERS(activeProject.id) : null,
- activeWorkspace && activeProject
- ? () => projectServices.projectMembers(activeWorkspace.slug, activeProject.id)
+ workspaceSlug && projectId ? PROJECT_MEMBERS(projectId as string) : null,
+ workspaceSlug && projectId
+ ? () => projectServices.projectMembers(workspaceSlug as string, projectId as string)
: null
);
diff --git a/apps/app/components/project/modules/create-update-module-modal/select-members.tsx b/apps/app/components/project/modules/create-update-module-modal/select-members.tsx
index bac370c629c..7ba0f82e7e1 100644
--- a/apps/app/components/project/modules/create-update-module-modal/select-members.tsx
+++ b/apps/app/components/project/modules/create-update-module-modal/select-members.tsx
@@ -1,14 +1,14 @@
-// react
import React from "react";
-// swr
+
+import { useRouter } from "next/router";
+
import useSWR from "swr";
-// react hook form
+
import { Controller } from "react-hook-form";
import type { Control } from "react-hook-form";
// service
import projectServices from "lib/services/project.service";
-// hooks
-import useUser from "lib/hooks/useUser";
+
// ui
import { SearchListbox } from "ui";
// icons
@@ -23,12 +23,13 @@ type Props = {
};
const SelectMembers: React.FC = ({ control }) => {
- const { activeWorkspace, activeProject } = useUser();
+ const router = useRouter();
+ const { workspaceSlug, projectId } = router.query;
const { data: people } = useSWR(
- activeWorkspace && activeProject ? PROJECT_MEMBERS(activeProject.id) : null,
- activeWorkspace && activeProject
- ? () => projectServices.projectMembers(activeWorkspace.slug, activeProject.id)
+ workspaceSlug && projectId ? PROJECT_MEMBERS(projectId as string) : null,
+ workspaceSlug && projectId
+ ? () => projectServices.projectMembers(workspaceSlug as string, projectId as string)
: null
);
diff --git a/apps/app/components/project/modules/list-view/index.tsx b/apps/app/components/project/modules/list-view/index.tsx
index 504e69db7b5..5f383416e81 100644
--- a/apps/app/components/project/modules/list-view/index.tsx
+++ b/apps/app/components/project/modules/list-view/index.tsx
@@ -1,14 +1,14 @@
-// react
import React from "react";
-// swr
+
+import { useRouter } from "next/router";
+
import useSWR from "swr";
// services
import workspaceService from "lib/services/workspace.service";
import stateService from "lib/services/state.service";
// common
import { addSpaceIfCamelCase } from "constants/common";
-// hooks
-import useUser from "lib/hooks/useUser";
+
// components
import SingleListIssue from "components/common/list-view/single-issue";
// headless ui
@@ -52,17 +52,18 @@ const ModulesListView: React.FC = ({
handleDeleteIssue,
setPreloadedData,
}) => {
- const { activeWorkspace, activeProject } = useUser();
+ const router = useRouter();
+ const { workspaceSlug, projectId } = router.query;
const { data: people } = useSWR(
- activeWorkspace ? WORKSPACE_MEMBERS : null,
- activeWorkspace ? () => workspaceService.workspaceMembers(activeWorkspace.slug) : null
+ workspaceSlug ? WORKSPACE_MEMBERS : null,
+ workspaceSlug ? () => workspaceService.workspaceMembers(workspaceSlug as string) : null
);
const { data: states } = useSWR(
- activeWorkspace && activeProject ? STATE_LIST(activeProject.id) : null,
- activeWorkspace && activeProject
- ? () => stateService.getStates(activeWorkspace.slug, activeProject.id)
+ workspaceSlug && projectId ? STATE_LIST(projectId as string) : null,
+ workspaceSlug && projectId
+ ? () => stateService.getStates(workspaceSlug as string, projectId as string)
: null
);
diff --git a/apps/app/components/project/modules/module-detail-sidebar/index.tsx b/apps/app/components/project/modules/module-detail-sidebar/index.tsx
index 519e5d6c819..cde22e8a742 100644
--- a/apps/app/components/project/modules/module-detail-sidebar/index.tsx
+++ b/apps/app/components/project/modules/module-detail-sidebar/index.tsx
@@ -1,16 +1,14 @@
-// react
-import { useEffect, useState } from "react";
-// next
+import React, { useEffect, useState } from "react";
+
import Link from "next/link";
import { useRouter } from "next/router";
-// swr
+
import { mutate } from "swr";
-// react-hook-form
+
import { Controller, useForm } from "react-hook-form";
// services
import modulesService from "lib/services/modules.service";
// hooks
-import useUser from "lib/hooks/useUser";
import useToast from "lib/hooks/useToast";
// components
import SelectMembers from "components/project/modules/module-detail-sidebar/select-members";
@@ -22,7 +20,6 @@ import { Loader } from "ui";
import {
CalendarDaysIcon,
ChartPieIcon,
- ClipboardDocumentIcon,
LinkIcon,
PlusIcon,
TrashIcon,
@@ -55,13 +52,12 @@ const ModuleDetailSidebar: React.FC = ({
moduleIssues,
handleDeleteModule,
}) => {
+ const [moduleLinkModal, setModuleLinkModal] = useState(false);
+
const router = useRouter();
const {
- query: { workspaceSlug },
+ query: { workspaceSlug, projectId },
} = router;
- const [moduleLinkModal, setModuleLinkModal] = useState(false);
-
- const { activeWorkspace, activeProject } = useUser();
const { setToastAlert } = useToast();
@@ -69,6 +65,14 @@ const ModuleDetailSidebar: React.FC = ({
defaultValues,
});
+ useEffect(() => {
+ if (module)
+ reset({
+ ...module,
+ members_list: module.members_list ?? module.members_detail?.map((m) => m.id),
+ });
+ }, [module, reset]);
+
const groupedIssues = {
backlog: [],
unstarted: [],
@@ -79,10 +83,10 @@ const ModuleDetailSidebar: React.FC = ({
};
const submitChanges = (data: Partial) => {
- if (!activeWorkspace || !activeProject || !module) return;
+ if (!workspaceSlug || !projectId || !module) return;
modulesService
- .patchModule(activeWorkspace.slug, activeProject.id, module.id, data)
+ .patchModule(workspaceSlug as string, projectId as string, module.id, data)
.then((res) => {
console.log(res);
mutate(MODULE_DETAIL);
@@ -92,14 +96,6 @@ const ModuleDetailSidebar: React.FC = ({
});
};
- useEffect(() => {
- if (module)
- reset({
- ...module,
- members_list: module.members_list ?? module.members_detail?.map((m) => m.id),
- });
- }, [module, reset]);
-
return (
<>
= ({
className="rounded-md border p-2 shadow-sm duration-300 hover:bg-gray-100 focus:border-indigo-500 focus:outline-none focus:ring-1 focus:ring-indigo-500"
onClick={() =>
copyTextToClipboard(
- `https://app.plane.so/${workspaceSlug}/projects/${activeProject?.id}/modules/${module.id}`
+ `https://app.plane.so/${workspaceSlug}/projects/${projectId}/modules/${module.id}`
)
.then(() => {
setToastAlert({
diff --git a/apps/app/components/project/modules/module-detail-sidebar/select-members.tsx b/apps/app/components/project/modules/module-detail-sidebar/select-members.tsx
index 5132ab1a660..8d261c788ee 100644
--- a/apps/app/components/project/modules/module-detail-sidebar/select-members.tsx
+++ b/apps/app/components/project/modules/module-detail-sidebar/select-members.tsx
@@ -1,15 +1,13 @@
-// react
import React from "react";
-// next
+
import Image from "next/image";
-// swr
+import { useRouter } from "next/router";
+
import useSWR from "swr";
-// react-hook-form
+
import { Control, Controller } from "react-hook-form";
// services
import workspaceService from "lib/services/workspace.service";
-// hooks
-import useUser from "lib/hooks/useUser";
// headless ui
import { Listbox, Transition } from "@headlessui/react";
// ui
@@ -29,17 +27,18 @@ type Props = {
};
const SelectMembers: React.FC = ({ control, submitChanges }) => {
- const { activeWorkspace } = useUser();
+ const router = useRouter();
+ const { workspaceSlug } = router.query;
const { data: people } = useSWR(
- activeWorkspace ? WORKSPACE_MEMBERS(activeWorkspace.slug) : null,
- activeWorkspace ? () => workspaceService.workspaceMembers(activeWorkspace.slug) : null
+ workspaceSlug ? WORKSPACE_MEMBERS(workspaceSlug as string) : null,
+ workspaceSlug ? () => workspaceService.workspaceMembers(workspaceSlug as string) : null
);
return (
-
+
@@ -58,14 +57,14 @@ const SelectMembers: React.FC
= ({ control, submitChanges }) => {
>
{({ open }) => (
-
+
-
+
{value && Array.isArray(value) ? (
<>
{value.length > 0 ? (
@@ -80,7 +79,7 @@ const SelectMembers: React.FC
= ({ control, submitChanges }) => {
}`}
>
{person && person.avatar && person.avatar !== "" ? (
-
+
= ({ control, submitChanges }) => {
) : (
{person?.first_name && person.first_name !== ""
? person.first_name.charAt(0)
@@ -102,7 +101,7 @@ const SelectMembers: React.FC
= ({ control, submitChanges }) => {
);
})
) : (
-
+
= ({ control, submitChanges }) => {
leaveFrom="transform opacity-100 scale-100"
leaveTo="transform opacity-0 scale-95"
>
-
+
{people ? (
people.length > 0 ? (
@@ -138,7 +137,7 @@ const SelectMembers: React.FC
= ({ control, submitChanges }) => {
className={({ active, selected }) =>
`${
active || selected ? "bg-indigo-50" : ""
- } flex items-center gap-2 text-gray-900 cursor-pointer select-none p-2 truncate`
+ } flex cursor-pointer select-none items-center gap-2 truncate p-2 text-gray-900`
}
value={option.member.id}
>
@@ -153,7 +152,7 @@ const SelectMembers: React.FC = ({ control, submitChanges }) => {
/>
) : (
-
+
{option.member.first_name && option.member.first_name !== ""
? option.member.first_name.charAt(0)
: option.member.email.charAt(0)}
diff --git a/apps/app/components/project/modules/module-link-modal.tsx b/apps/app/components/project/modules/module-link-modal.tsx
index c38bd2642ee..fc40e8e94b8 100644
--- a/apps/app/components/project/modules/module-link-modal.tsx
+++ b/apps/app/components/project/modules/module-link-modal.tsx
@@ -1,10 +1,11 @@
-// react
-import React, { useEffect } from "react";
-// swr
+import React from "react";
+
+import { useRouter } from "next/router";
+
import { mutate } from "swr";
-// react hook form
+
import { useForm } from "react-hook-form";
-// headless
+
import { Dialog, Transition } from "@headlessui/react";
// services
import modulesService from "lib/services/modules.service";
@@ -29,15 +30,8 @@ const defaultValues: ModuleLink = {
};
const ModuleLinkModal: React.FC
= ({ isOpen, module, handleClose }) => {
- const { activeWorkspace, activeProject } = useUser();
-
- const onClose = () => {
- handleClose();
- const timeout = setTimeout(() => {
- reset(defaultValues);
- clearTimeout(timeout);
- }, 500);
- };
+ const router = useRouter();
+ const { workspaceSlug, projectId } = router.query;
const {
register,
@@ -50,7 +44,7 @@ const ModuleLinkModal: React.FC = ({ isOpen, module, handleClose }) => {
});
const onSubmit = async (formData: ModuleLink) => {
- if (!activeWorkspace || !activeProject || !module) return;
+ if (!workspaceSlug || !projectId || !module) return;
const previousLinks = module.link_module.map((l) => {
return { title: l.title, url: l.url };
@@ -61,7 +55,7 @@ const ModuleLinkModal: React.FC = ({ isOpen, module, handleClose }) => {
};
await modulesService
- .patchModule(activeWorkspace.slug, activeProject.id, module.id, payload)
+ .patchModule(workspaceSlug as string, projectId as string, module.id, payload)
.then((res) => {
mutate(MODULE_DETAIL);
onClose();
@@ -75,6 +69,14 @@ const ModuleLinkModal: React.FC = ({ isOpen, module, handleClose }) => {
});
};
+ const onClose = () => {
+ handleClose();
+ const timeout = setTimeout(() => {
+ reset(defaultValues);
+ clearTimeout(timeout);
+ }, 500);
+ };
+
return (
diff --git a/apps/app/components/project/send-project-invitation-modal.tsx b/apps/app/components/project/send-project-invitation-modal.tsx
index ef77b65f90f..a4178c984f8 100644
--- a/apps/app/components/project/send-project-invitation-modal.tsx
+++ b/apps/app/components/project/send-project-invitation-modal.tsx
@@ -1,9 +1,11 @@
import React from "react";
-// swr
+
+import { useRouter } from "next/router";
+
import useSWR, { mutate } from "swr";
-// react hook form
+
import { useForm, Controller } from "react-hook-form";
-// headless
+
import { Dialog, Transition, Listbox } from "@headlessui/react";
// hooks
import useUser from "lib/hooks/useUser";
@@ -42,24 +44,17 @@ const defaultValues: Partial = {
};
const SendProjectInvitationModal: React.FC = ({ isOpen, setIsOpen, members }) => {
- const handleClose = () => {
- setIsOpen(false);
- const timeout = setTimeout(() => {
- reset(defaultValues);
- clearTimeout(timeout);
- }, 500);
- };
-
- const { activeWorkspace, activeProject } = useUser();
+ const router = useRouter();
+ const { workspaceSlug, projectId } = router.query;
const { setToastAlert } = useToast();
const { data: people } = useSWR(
- activeWorkspace ? WORKSPACE_MEMBERS(activeWorkspace.slug) : null,
- activeWorkspace ? () => workspaceService.workspaceMembers(activeWorkspace.slug) : null,
+ workspaceSlug ? WORKSPACE_MEMBERS(workspaceSlug as string) : null,
+ workspaceSlug ? () => workspaceService.workspaceMembers(workspaceSlug as string) : null,
{
onErrorRetry(err, _, __, revalidate, revalidateOpts) {
- if (err?.status === 403) return;
+ if (err?.status === 403 || err?.status === 401) return;
setTimeout(() => revalidate(revalidateOpts), 5000);
},
}
@@ -70,7 +65,6 @@ const SendProjectInvitationModal: React.FC = ({ isOpen, setIsOpen, member
formState: { errors, isSubmitting },
handleSubmit,
reset,
- setError,
setValue,
control,
} = useForm({
@@ -78,11 +72,10 @@ const SendProjectInvitationModal: React.FC = ({ isOpen, setIsOpen, member
});
const onSubmit = async (formData: ProjectMember) => {
- if (!activeWorkspace || !activeProject || isSubmitting) return;
+ if (!workspaceSlug || !projectId || isSubmitting) return;
await projectService
- .inviteProject(activeWorkspace.slug, activeProject.id, formData)
+ .inviteProject(workspaceSlug as string, projectId as string, formData)
.then((response) => {
- console.log(response);
setIsOpen(false);
mutate(
PROJECT_INVITATIONS,
@@ -102,6 +95,14 @@ const SendProjectInvitationModal: React.FC = ({ isOpen, setIsOpen, member
});
};
+ const handleClose = () => {
+ setIsOpen(false);
+ const timeout = setTimeout(() => {
+ reset(defaultValues);
+ clearTimeout(timeout);
+ }, 500);
+ };
+
return (
@@ -156,12 +157,12 @@ const SendProjectInvitationModal: React.FC = ({ isOpen, setIsOpen, member
>
{({ open }) => (
<>
-
+
Email
@@ -170,7 +171,7 @@ const SendProjectInvitationModal: React.FC = ({ isOpen, setIsOpen, member
? people?.find((p) => p.member.id === value)?.member.email
: "Select email"}
-
+
= ({ isOpen, setIsOpen, member
leaveFrom="opacity-100"
leaveTo="opacity-0"
>
-
+
{people?.map(
(person) =>
!members.some(
@@ -195,8 +196,8 @@ const SendProjectInvitationModal: React.FC = ({ isOpen, setIsOpen, member
key={person.member.id}
className={({ active }) =>
`${
- active ? "text-white bg-theme" : "text-gray-900"
- } cursor-default select-none relative py-2 pl-3 pr-9 text-left`
+ active ? "bg-theme text-white" : "text-gray-900"
+ } relative cursor-default select-none py-2 pl-3 pr-9 text-left`
}
value={{
id: person.member.id,
diff --git a/apps/app/components/workspace/confirm-workspace-deletion.tsx b/apps/app/components/workspace/confirm-workspace-deletion.tsx
index 79eeab86c36..ac5eef0980d 100644
--- a/apps/app/components/workspace/confirm-workspace-deletion.tsx
+++ b/apps/app/components/workspace/confirm-workspace-deletion.tsx
@@ -1,12 +1,11 @@
import React, { useEffect, useRef, useState } from "react";
-// next
+
import { useRouter } from "next/router";
-// headless ui
+
import { Dialog, Transition } from "@headlessui/react";
// services
import workspaceService from "lib/services/workspace.service";
// hooks
-import useUser from "lib/hooks/useUser";
import useToast from "lib/hooks/useToast";
// icons
import { ExclamationTriangleIcon } from "@heroicons/react/24/outline";
@@ -22,22 +21,26 @@ type Props = {
};
const ConfirmWorkspaceDeletion: React.FC = ({ isOpen, data, onClose }) => {
- const router = useRouter();
-
+ const cancelButtonRef = useRef(null);
const [isDeleteLoading, setIsDeleteLoading] = useState(false);
-
- const [selectedWorkspace, setSelectedWorkspace] = useState(null);
-
const [confirmProjectName, setConfirmProjectName] = useState("");
const [confirmDeleteMyProject, setConfirmDeleteMyProject] = useState(false);
+ const [selectedWorkspace, setSelectedWorkspace] = useState(null);
- const canDelete = confirmProjectName === data?.name && confirmDeleteMyProject;
-
- const { mutateWorkspaces } = useUser();
-
+ const router = useRouter();
const { setToastAlert } = useToast();
- const cancelButtonRef = useRef(null);
+ useEffect(() => {
+ if (data) setSelectedWorkspace(data);
+ else {
+ const timer = setTimeout(() => {
+ setSelectedWorkspace(null);
+ clearTimeout(timer);
+ }, 350);
+ }
+ }, [data]);
+
+ const canDelete = confirmProjectName === data?.name && confirmDeleteMyProject;
const handleClose = () => {
onClose();
@@ -51,9 +54,7 @@ const ConfirmWorkspaceDeletion: React.FC = ({ isOpen, data, onClose }) =>
.deleteWorkspace(data.slug)
.then(() => {
handleClose();
- mutateWorkspaces((prevData) => {
- return (prevData ?? []).filter((workspace: IWorkspace) => workspace.slug !== data.slug);
- }, false);
+ // TODO: add workspace mutation
setToastAlert({
type: "success",
message: "Workspace deleted successfully",
@@ -67,16 +68,6 @@ const ConfirmWorkspaceDeletion: React.FC = ({ isOpen, data, onClose }) =>
});
};
- useEffect(() => {
- if (data) setSelectedWorkspace(data);
- else {
- const timer = setTimeout(() => {
- setSelectedWorkspace(null);
- clearTimeout(timer);
- }, 350);
- }
- }, [data]);
-
return (
;
- activeWorkspace?: IWorkspace;
- mutateWorkspaces: KeyedMutator;
- workspaces?: IWorkspace[];
- projects?: IProject[];
- setActiveProject: React.Dispatch>;
- mutateProjects: KeyedMutator;
- activeProject?: IProject;
- slug?: string;
}
export const UserContext = createContext({} as IUserContextProps);
export const UserProvider = ({ children }: { children: ReactElement }) => {
- const [activeWorkspace, setActiveWorkspace] = useState();
- const [activeProject, setActiveProject] = useState();
-
- const router = useRouter();
-
- const { projectId } = router.query;
-
// API to fetch user information
const {
data: user,
@@ -48,65 +28,12 @@ export const UserProvider = ({ children }: { children: ReactElement }) => {
shouldRetryOnError: false,
});
- const {
- data: workspaces,
- error: workspaceError,
- mutate: mutateWorkspaces,
- } = useSWR(
- user ? USER_WORKSPACES : null,
- user ? () => workspaceService.userWorkspaces() : null,
- {
- shouldRetryOnError: false,
- }
- );
-
- const { data: projects, mutate: mutateProjects } = useSWR(
- activeWorkspace ? PROJECTS_LIST(activeWorkspace.slug) : null,
- activeWorkspace ? () => projectServices.getProjects(activeWorkspace.slug) : null
- );
-
- useEffect(() => {
- if (!projects) return;
- const activeProject = projects.find((project) => project.id === projectId);
- setActiveProject(activeProject ?? projects[0]);
- }, [projectId, projects]);
-
- useEffect(() => {
- if (user?.last_workspace_id) {
- const workspace = workspaces?.find((item) => item.id === user?.last_workspace_id);
- if (workspace) {
- setActiveWorkspace(workspace);
- } else {
- const workspace = workspaces?.[0];
- setActiveWorkspace(workspace);
- userService.updateUser({ last_workspace_id: workspace?.id });
- }
- } else if (user) {
- const workspace = workspaces?.[0];
- setActiveWorkspace(workspace);
- userService.updateUser({ last_workspace_id: workspace?.id });
- }
- }, [user, workspaces]);
-
- useEffect(() => {
- if (!workspaces) return;
- if (workspaces.length === 0) Router.push("/invitations");
- }, [workspaces]);
-
return (
{children}
diff --git a/apps/app/lib/auth.ts b/apps/app/lib/auth.ts
index ba9ffd0fc1a..75b7b67605f 100644
--- a/apps/app/lib/auth.ts
+++ b/apps/app/lib/auth.ts
@@ -1,9 +1,15 @@
import { convertCookieStringToObject } from "./cookie";
// types
-import type { IProjectMember, IUser } from "types";
+import type { IProjectMember, IUser, IWorkspace } from "types";
// constants
-import { BASE_STAGING, PROJECT_MEMBER_ME, USER_ENDPOINT } from "constants/api-routes";
+import {
+ BASE_STAGING,
+ PROJECT_MEMBER_ME,
+ USER_ENDPOINT,
+ USER_WORKSPACES,
+ USER_WORKSPACE_INVITATIONS,
+} from "constants/api-routes";
export const requiredAuth = async (cookie?: string) => {
const cookies = convertCookieStringToObject(cookie);
@@ -49,6 +55,7 @@ export const requiredAdmin = async (workspaceSlug: string, projectId: string, co
try {
const data = await fetch(`${baseUrl}${PROJECT_MEMBER_ME(workspaceSlug, projectId)}`, {
+ method: "GET",
headers: {
Authorization: `Bearer ${token}`,
},
@@ -64,3 +71,95 @@ export const requiredAdmin = async (workspaceSlug: string, projectId: string, co
return memberDetail || null;
};
+
+export const homePageRedirect = async (cookie?: string) => {
+ const user = await requiredAuth(cookie);
+
+ if (!user)
+ return {
+ redirect: {
+ destination: "/signin",
+ permanent: false,
+ },
+ };
+
+ // FIXME: backend is returning object of user and workspace.
+ // Get KT if it's required to send user and workspace and if
+ // yes change below accordingly
+ if (!user.is_onboarded)
+ return {
+ redirect: {
+ destination: "/invitations",
+ permanent: false,
+ },
+ };
+
+ let workspaces: IWorkspace[] = [];
+
+ const baseUrl = process.env.NEXT_PUBLIC_API_BASE_URL || BASE_STAGING;
+
+ const cookies = convertCookieStringToObject(cookie);
+ const token = cookies?.accessToken;
+
+ try {
+ const data = await fetch(`${baseUrl}${USER_WORKSPACES}`, {
+ method: "GET",
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: `Bearer ${token}`,
+ },
+ })
+ .then((res) => res.json())
+ .then((data) => data);
+
+ workspaces = data;
+ } catch (e) {
+ console.error(e);
+ }
+
+ const lastActiveWorkspace = workspaces.find(
+ (workspace) => workspace.id === user.last_workspace_id
+ );
+
+ if (lastActiveWorkspace) {
+ return {
+ redirect: {
+ destination: `/${lastActiveWorkspace.slug}`,
+ permanent: false,
+ },
+ };
+ } else if (workspaces.length > 0) {
+ return {
+ redirect: {
+ destination: `/${workspaces[0].slug}`,
+ permanent: false,
+ },
+ };
+ }
+
+ const invitations = await fetch(`${baseUrl}${USER_WORKSPACE_INVITATIONS}`, {
+ method: "GET",
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: `Bearer ${token}`,
+ },
+ })
+ .then((res) => res.json())
+ .then((data) => data);
+
+ if (invitations.length > 0)
+ return {
+ redirect: {
+ destination: "/invitations",
+ permanent: false,
+ },
+ };
+ else {
+ return {
+ redirect: {
+ destination: "/create-workspace",
+ permanent: false,
+ },
+ };
+ }
+};
diff --git a/apps/app/lib/hooks/useMyIssueFilter.tsx b/apps/app/lib/hooks/useMyIssueFilter.tsx
index 2075b1f8829..18f764dda3c 100644
--- a/apps/app/lib/hooks/useMyIssueFilter.tsx
+++ b/apps/app/lib/hooks/useMyIssueFilter.tsx
@@ -1,5 +1,7 @@
import { useEffect, useState } from "react";
-// swr
+
+import { useRouter } from "next/router";
+
import useSWR from "swr";
// constants
import { STATE_LIST } from "constants/fetch-keys";
@@ -30,12 +32,16 @@ const useMyIssuesProperties = (issues?: IIssue[]) => {
const [properties, setProperties] = useState(initialValues);
const [groupByProperty, setGroupByProperty] = useState | null>(null);
- const { activeWorkspace, activeProject, user } = useUser();
+ // FIXME: where this hook is used we may not have project id in the url
+ const router = useRouter();
+ const { workspaceSlug, projectId } = router.query;
+
+ const { user } = useUser();
const { data: states } = useSWR(
- activeWorkspace && activeProject ? STATE_LIST(activeProject.id) : null,
- activeWorkspace && activeProject
- ? () => stateService.getStates(activeWorkspace.slug, activeProject.id)
+ workspaceSlug && projectId ? STATE_LIST(projectId as string) : null,
+ workspaceSlug && projectId
+ ? () => stateService.getStates(workspaceSlug as string, projectId as string)
: null
);
diff --git a/apps/app/pages/[workspaceSlug]/projects/[projectId]/issues/[issueId].tsx b/apps/app/pages/[workspaceSlug]/projects/[projectId]/issues/[issueId].tsx
index c5143476c69..c38f4b2f031 100644
--- a/apps/app/pages/[workspaceSlug]/projects/[projectId]/issues/[issueId].tsx
+++ b/apps/app/pages/[workspaceSlug]/projects/[projectId]/issues/[issueId].tsx
@@ -84,29 +84,22 @@ const IssueDetail: NextPage = () => {
);
const { data: activeProject } = useSWR(
- activeWorkspace && projectId ? PROJECT_DETAILS(projectId as string) : null,
- activeWorkspace && projectId
- ? () => projectService.getProject(activeWorkspace.slug, projectId as string)
+ workspaceSlug && projectId ? PROJECT_DETAILS(projectId as string) : null,
+ workspaceSlug && projectId
+ ? () => projectService.getProject(workspaceSlug as string, projectId as string)
: null
);
const { data: issues, mutate: mutateIssues } = useSWR(
- activeWorkspace && activeProject
- ? PROJECT_ISSUES_LIST(activeWorkspace.slug, activeProject.id)
+ workspaceSlug && projectId
+ ? PROJECT_ISSUES_LIST(workspaceSlug as string, projectId as string)
: null,
- activeWorkspace && activeProject
- ? () => issuesServices.getIssues(activeWorkspace.slug, activeProject.id)
+ workspaceSlug && projectId
+ ? () => issuesServices.getIssues(workspaceSlug as string, projectId as string)
: null
);
- const {
- register,
- formState: { errors },
- handleSubmit,
- reset,
- control,
- watch,
- } = useForm({
+ const { register, handleSubmit, reset, control, watch } = useForm({
defaultValues,
});
diff --git a/apps/app/pages/[workspaceSlug]/projects/[projectId]/issues/index.tsx b/apps/app/pages/[workspaceSlug]/projects/[projectId]/issues/index.tsx
index e30e5a1a88f..4f73117a413 100644
--- a/apps/app/pages/[workspaceSlug]/projects/[projectId]/issues/index.tsx
+++ b/apps/app/pages/[workspaceSlug]/projects/[projectId]/issues/index.tsx
@@ -64,18 +64,18 @@ const ProjectIssues: NextPage = () => {
);
const { data: activeProject } = useSWR(
- activeWorkspace && projectId ? PROJECT_DETAILS(projectId as string) : null,
- activeWorkspace && projectId
- ? () => projectService.getProject(activeWorkspace.slug, projectId as string)
+ workspaceSlug && projectId ? PROJECT_DETAILS(projectId as string) : null,
+ workspaceSlug && projectId
+ ? () => projectService.getProject(workspaceSlug as string, projectId as string)
: null
);
const { data: projectIssues } = useSWR(
activeWorkspace && activeProject
- ? PROJECT_ISSUES_LIST(activeWorkspace.slug, activeProject.id)
+ ? PROJECT_ISSUES_LIST(workspaceSlug as string, projectId as string)
: null,
activeWorkspace && activeProject
- ? () => issuesServices.getIssues(activeWorkspace.slug, activeProject.id)
+ ? () => issuesServices.getIssues(workspaceSlug as string, projectId as string)
: null
);
diff --git a/apps/app/pages/create-workspace.tsx b/apps/app/pages/create-workspace.tsx
index 92b1830d49c..508a74684be 100644
--- a/apps/app/pages/create-workspace.tsx
+++ b/apps/app/pages/create-workspace.tsx
@@ -31,14 +31,14 @@ const CreateWorkspace: NextPage = () => {
const router = useRouter();
- const { mutateWorkspaces, user } = useUser();
+ const { user } = useUser();
const onSubmit = async (formData: IWorkspace) => {
await workspaceService
.createWorkspace(formData)
.then((res) => {
console.log(res);
- mutateWorkspaces((prevData) => [...(prevData ?? []), res], false);
+ // TODO: add workspace mutations
router.push("/");
})
.catch((err) => {
diff --git a/apps/app/pages/index.tsx b/apps/app/pages/index.tsx
index 98d151d2137..f1b8fa4a7bf 100644
--- a/apps/app/pages/index.tsx
+++ b/apps/app/pages/index.tsx
@@ -1,25 +1,17 @@
import React, { useEffect } from "react";
-// next
-import type { NextPage } from "next";
-import { useRouter } from "next/router";
-// hooks
-import useUser from "lib/hooks/useUser";
-const Home: NextPage = () => {
- const router = useRouter();
-
- const { user, isUserLoading, activeWorkspace, workspaces, slug } = useUser();
+import type { NextPage, NextPageContext } from "next";
- useEffect(() => {
- if (!isUserLoading && (!user || user === null)) router.push("/signin");
- }, [isUserLoading, user, router]);
+// lib
+import { homePageRedirect } from "lib/auth";
- useEffect(() => {
- if (slug) router.push(`/${slug}`);
- else if (!activeWorkspace && workspaces?.length === 0) router.push("/invitations");
- }, [activeWorkspace, router, workspaces, slug]);
+const Home: NextPage = () => {
+ return null;
+};
- return <>>;
+export const getServerSideProps = (ctx: NextPageContext) => {
+ const cookies = ctx.req?.headers.cookie;
+ return homePageRedirect(cookies);
};
export default Home;
diff --git a/apps/app/pages/invitations.tsx b/apps/app/pages/invitations.tsx
index 18daeddb0c9..699b2fd327f 100644
--- a/apps/app/pages/invitations.tsx
+++ b/apps/app/pages/invitations.tsx
@@ -1,17 +1,18 @@
import React, { useState } from "react";
-// next
+
import Link from "next/link";
import { useRouter } from "next/router";
import type { NextPage, NextPageContext } from "next";
-// swr
+
import useSWR from "swr";
// services
-import workspaceService from "lib/services/workspace.service";
import userService from "lib/services/user.service";
+import workspaceService from "lib/services/workspace.service";
// hooks
import useUser from "lib/hooks/useUser";
// constants
import { requiredAuth } from "lib/auth";
+import { USER_WORKSPACES } from "constants/fetch-keys";
import { USER_WORKSPACE_INVITATIONS } from "constants/api-routes";
// layouts
import DefaultLayout from "layouts/DefaultLayout";
@@ -27,7 +28,7 @@ import type { IWorkspaceMemberInvitation } from "types";
const OnBoard: NextPage = () => {
const [invitationsRespond, setInvitationsRespond] = useState([]);
- const { workspaces, mutateWorkspaces, user, slug } = useUser();
+ const { user } = useUser();
const router = useRouter();
@@ -35,6 +36,8 @@ const OnBoard: NextPage = () => {
workspaceService.userWorkspaceInvitations()
);
+ const { data: workspaces } = useSWR(USER_WORKSPACES, () => workspaceService.userWorkspaces());
+
const handleInvitation = (
workspace_invitation: IWorkspaceMemberInvitation,
action: "accepted" | "withdraw"
@@ -50,17 +53,14 @@ const OnBoard: NextPage = () => {
}
};
- const submitInvitations = () => {
- userService.updateUserOnBoard().then((response) => {
- console.log(response);
- });
+ const submitInvitations = async () => {
+ await userService.updateUserOnBoard().then((response) => {});
workspaceService
.joinWorkspaces({ invitations: invitationsRespond })
.then(async (res: any) => {
console.log(res);
await mutate();
- await mutateWorkspaces();
- router.push(slug || "");
+ // TODO: add workspace mutations
})
.catch((err) => {
console.log(err);
@@ -104,11 +104,7 @@ const OnBoard: NextPage = () => {
))}
- router.push(`/${slug}` || "/create-workspace")}
- >
+ router.push("/")}>
Skip
@@ -135,7 +131,7 @@ const OnBoard: NextPage = () => {
))}
-
+
Go to workspaces
diff --git a/apps/app/pages/magic-sign-in.tsx b/apps/app/pages/magic-sign-in.tsx
index 6a88e9c1826..8d978297c82 100644
--- a/apps/app/pages/magic-sign-in.tsx
+++ b/apps/app/pages/magic-sign-in.tsx
@@ -20,7 +20,7 @@ const MagicSignIn: NextPage = () => {
const { setToastAlert } = useToast();
- const { mutateUser, mutateWorkspaces } = useUser();
+ const { mutateUser } = useUser();
useEffect(() => {
setIsSigningIn(true);
@@ -31,7 +31,7 @@ const MagicSignIn: NextPage = () => {
.then(async (res) => {
setIsSigningIn(false);
await mutateUser();
- await mutateWorkspaces();
+ // TODO: add workspace mutations
if (res.user.is_onboarded) router.push("/");
else router.push("/invitations");
})
@@ -39,7 +39,7 @@ const MagicSignIn: NextPage = () => {
setErrorSignIn(err.response.data.error);
setIsSigningIn(false);
});
- }, [password, key, mutateUser, mutateWorkspaces, router]);
+ }, [password, key, mutateUser, router]);
return (
{
title: "Magic Sign In",
}}
>
-
+
{isSigningIn ? (
-
+
Signing you in...
Please wait while we are preparing your take off.
) : errorSigningIn ? (
-
+
Error
{errorSigningIn}.
{
authenticationService
.emailCode({ email: (key as string).split("_")[1] })
@@ -86,7 +86,7 @@ const MagicSignIn: NextPage = () => {
) : (
-
+
Success
Redirecting you to the app...
diff --git a/apps/app/pages/signin.tsx b/apps/app/pages/signin.tsx
index e4d3afe3c54..6442845f11f 100644
--- a/apps/app/pages/signin.tsx
+++ b/apps/app/pages/signin.tsx
@@ -34,7 +34,7 @@ const SignIn: NextPage = () => {
const [useCode, setUseCode] = useState(true);
const router = useRouter();
- const { mutateUser, mutateWorkspaces, slug } = useUser();
+ const { mutateUser } = useUser();
const [githubToken, setGithubToken] = useState(undefined);
const [loginCallBackURL, setLoginCallBackURL] = useState(undefined);
@@ -44,16 +44,17 @@ const SignIn: NextPage = () => {
const onSignInSuccess = useCallback(
async (res: IUser) => {
await mutateUser();
- await mutateWorkspaces();
+ // TODO: add mutate workspaces
const nextLocation = router.asPath.split("?next=")[1];
if (nextLocation) {
router.push(nextLocation as string);
} else {
if (!res.user.is_onboarded) router.push("/invitations");
+ else router.push("/");
}
},
- [mutateUser, mutateWorkspaces, router]
+ [mutateUser, router]
);
const githubTokenMemo = React.useMemo(() => {
@@ -84,7 +85,7 @@ const SignIn: NextPage = () => {
console.log(err);
});
}
- }, [githubToken, mutateUser, mutateWorkspaces, router, onSignInSuccess]);
+ }, [githubToken, mutateUser, router, onSignInSuccess]);
useEffect(() => {
const origin =
@@ -94,10 +95,6 @@ const SignIn: NextPage = () => {
return () => setIsGoogleAuthenticationLoading(false);
}, []);
- if (slug) {
- router.push(`/${slug}`);
- }
-
return (
| null;
diff --git a/apps/app/ui/search-listbox/index.tsx b/apps/app/ui/search-listbox/index.tsx
index df5bbac1c09..055371d9685 100644
--- a/apps/app/ui/search-listbox/index.tsx
+++ b/apps/app/ui/search-listbox/index.tsx
@@ -1,13 +1,11 @@
-// react
import React, { useState } from "react";
-// next
+
import Image from "next/image";
-// swr
+import { useRouter } from "next/router";
+
import useSWR from "swr";
// services
import workspaceService from "lib/services/workspace.service";
-// hooks
-import useUser from "lib/hooks/useUser";
// headless ui
import { Transition, Combobox } from "@headlessui/react";
// types
@@ -32,7 +30,8 @@ const SearchListbox: React.FC = ({
}) => {
const [query, setQuery] = useState("");
- const { activeWorkspace } = useUser();
+ const router = useRouter();
+ const { workspaceSlug } = router.query;
const filteredOptions =
query === ""
@@ -53,8 +52,8 @@ const SearchListbox: React.FC = ({
}
const { data: people } = useSWR(
- activeWorkspace ? WORKSPACE_MEMBERS(activeWorkspace.slug) : null,
- activeWorkspace ? () => workspaceService.workspaceMembers(activeWorkspace.slug) : null
+ workspaceSlug ? WORKSPACE_MEMBERS(workspaceSlug as string) : null,
+ workspaceSlug ? () => workspaceService.workspaceMembers(workspaceSlug as string) : null
);
const userAvatar = (userId: string) => {
@@ -76,7 +75,7 @@ const SearchListbox: React.FC = ({
);
} else
return (
-
+
{user.member.first_name && user.member.first_name !== ""
? user.member.first_name.charAt(0)
: user.member.email.charAt(0)}
@@ -90,7 +89,7 @@ const SearchListbox: React.FC
= ({
<>
{title}
@@ -117,7 +116,7 @@ const SearchListbox: React.FC = ({
leaveTo="opacity-0"
>
= ({
} ${optionsClassName || ""}`}
>
setQuery(event.target.value)}
placeholder="Search"
displayValue={(assigned: any) => assigned?.name}
@@ -160,7 +159,7 @@ const SearchListbox: React.FC = ({
className={({ active }) =>
`${
active ? "bg-indigo-50" : ""
- } flex items-center gap-2 cursor-pointer select-none truncate text-gray-900 p-2`
+ } flex cursor-pointer select-none items-center gap-2 truncate p-2 text-gray-900`
}
value={option.value}
>