|
2 | 2 |
|
3 | 3 | import { useEffect } from "react"; |
4 | 4 | import { observer } from "mobx-react"; |
5 | | -import { useParams } from "next/navigation"; |
| 5 | +import { redirect, useParams } from "next/navigation"; |
| 6 | +import { useTheme } from "next-themes"; |
| 7 | +import useSWR from "swr"; |
| 8 | +import { useTranslation } from "@plane/i18n"; |
6 | 9 | // components |
7 | | -import { LogoSpinner } from "@/components/common"; |
| 10 | +import { EmptyState, LogoSpinner } from "@/components/common"; |
8 | 11 | // hooks |
9 | 12 | import { useAppRouter } from "@/hooks/use-app-router"; |
| 13 | +// assets |
| 14 | +import emptyIssueDark from "@/public/empty-state/search/issues-dark.webp"; |
| 15 | +import emptyIssueLight from "@/public/empty-state/search/issues-light.webp"; |
10 | 16 | // services |
11 | 17 | import { IssueService } from "@/services/issue/issue.service"; |
12 | 18 |
|
13 | 19 | const issueService = new IssueService(); |
14 | 20 |
|
15 | 21 | const IssueDetailsPage = observer(() => { |
16 | 22 | const router = useAppRouter(); |
| 23 | + const { t } = useTranslation(); |
17 | 24 | const { workspaceSlug, projectId, issueId } = useParams(); |
| 25 | + const { resolvedTheme } = useTheme(); |
18 | 26 |
|
19 | | - useEffect(() => { |
20 | | - const redirectToBrowseUrl = async () => { |
21 | | - if (!workspaceSlug || !projectId || !issueId) return; |
22 | | - try { |
23 | | - const meta = await issueService.getIssueMetaFromURL( |
24 | | - workspaceSlug.toString(), |
25 | | - projectId.toString(), |
26 | | - issueId.toString() |
27 | | - ); |
28 | | - router.push(`/${workspaceSlug}/browse/${meta.project_identifier}-${meta.sequence_id}`); |
29 | | - } catch (error) { |
30 | | - console.error(error); |
31 | | - } |
32 | | - }; |
| 27 | + const { data, isLoading, error } = useSWR( |
| 28 | + workspaceSlug && projectId && issueId ? `ISSUE_DETAIL_META_${workspaceSlug}_${projectId}_${issueId}` : null, |
| 29 | + workspaceSlug && projectId && issueId |
| 30 | + ? () => issueService.getIssueMetaFromURL(workspaceSlug.toString(), projectId.toString(), issueId.toString()) |
| 31 | + : null |
| 32 | + ); |
33 | 33 |
|
34 | | - redirectToBrowseUrl(); |
35 | | - }, [workspaceSlug, projectId, issueId, router]); |
| 34 | + useEffect(() => { |
| 35 | + if (data) { |
| 36 | + redirect(`/${workspaceSlug}/browse/${data.project_identifier}-${data.sequence_id}`); |
| 37 | + } |
| 38 | + }, [workspaceSlug, data]); |
36 | 39 |
|
37 | 40 | return ( |
38 | 41 | <div className="flex items-center justify-center size-full"> |
39 | | - <LogoSpinner /> |
| 42 | + {error ? ( |
| 43 | + <EmptyState |
| 44 | + image={resolvedTheme === "dark" ? emptyIssueDark : emptyIssueLight} |
| 45 | + title={t("issue.empty_state.issue_detail.title")} |
| 46 | + description={t("issue.empty_state.issue_detail.description")} |
| 47 | + primaryButton={{ |
| 48 | + text: t("issue.empty_state.issue_detail.primary_button.text"), |
| 49 | + onClick: () => router.push(`/${workspaceSlug}/workspace-views/all-issues/`), |
| 50 | + }} |
| 51 | + /> |
| 52 | + ) : isLoading ? ( |
| 53 | + <> |
| 54 | + <LogoSpinner /> |
| 55 | + </> |
| 56 | + ) : ( |
| 57 | + <></> |
| 58 | + )} |
40 | 59 | </div> |
41 | 60 | ); |
42 | 61 | }); |
|
0 commit comments