2023-04-08 08:16:46 +00:00
|
|
|
import { useState } from "react";
|
|
|
|
|
|
|
|
import Image from "next/image";
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
|
|
|
import { mutate } from "swr";
|
|
|
|
|
2023-04-17 04:57:20 +00:00
|
|
|
// services
|
|
|
|
import projectService from "services/project.service";
|
2023-04-08 08:16:46 +00:00
|
|
|
// ui
|
|
|
|
import { PrimaryButton } from "components/ui";
|
2023-04-17 04:57:20 +00:00
|
|
|
// icons
|
2023-04-08 08:16:46 +00:00
|
|
|
import { AssignmentClipboardIcon } from "components/icons";
|
2023-04-17 04:57:20 +00:00
|
|
|
// images
|
2023-04-08 08:16:46 +00:00
|
|
|
import JoinProjectImg from "public/auth/project-not-authorized.svg";
|
|
|
|
// fetch-keys
|
2023-04-17 04:57:20 +00:00
|
|
|
import { USER_PROJECT_VIEW } from "constants/fetch-keys";
|
2023-04-08 08:16:46 +00:00
|
|
|
|
|
|
|
export const JoinProject: React.FC = () => {
|
|
|
|
const [isJoiningProject, setIsJoiningProject] = useState(false);
|
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug, projectId } = router.query;
|
|
|
|
|
|
|
|
const handleJoin = () => {
|
2023-04-17 04:57:20 +00:00
|
|
|
if (!workspaceSlug || !projectId) return;
|
|
|
|
|
2023-04-08 08:16:46 +00:00
|
|
|
setIsJoiningProject(true);
|
|
|
|
projectService
|
|
|
|
.joinProject(workspaceSlug as string, {
|
|
|
|
project_ids: [projectId as string],
|
|
|
|
})
|
2023-04-17 04:57:20 +00:00
|
|
|
.then(async () => {
|
2023-04-18 05:25:32 +00:00
|
|
|
await mutate(USER_PROJECT_VIEW(projectId.toString()));
|
2023-04-17 04:57:20 +00:00
|
|
|
setIsJoiningProject(false);
|
2023-04-08 08:16:46 +00:00
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
console.error(err);
|
2023-04-11 11:43:06 +00:00
|
|
|
setIsJoiningProject(false);
|
2023-04-08 08:16:46 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2023-07-10 07:17:00 +00:00
|
|
|
<div className="flex h-full w-full flex-col items-center justify-center gap-y-5 bg-custom-background-90 text-center">
|
2023-04-08 08:16:46 +00:00
|
|
|
<div className="h-44 w-72">
|
|
|
|
<Image src={JoinProjectImg} height="176" width="288" alt="JoinProject" />
|
|
|
|
</div>
|
2023-07-10 07:17:00 +00:00
|
|
|
<h1 className="text-xl font-medium text-custom-text-100">
|
|
|
|
You are not a member of this project
|
|
|
|
</h1>
|
2023-04-08 08:16:46 +00:00
|
|
|
|
2023-07-10 07:17:00 +00:00
|
|
|
<div className="w-full max-w-md text-base text-custom-text-200">
|
2023-04-08 08:16:46 +00:00
|
|
|
<p className="mx-auto w-full text-sm md:w-3/4">
|
|
|
|
You are not a member of this project, but you can join this project by clicking the button
|
|
|
|
below.
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<PrimaryButton
|
|
|
|
className="flex items-center gap-1"
|
|
|
|
loading={isJoiningProject}
|
|
|
|
onClick={handleJoin}
|
|
|
|
>
|
|
|
|
<AssignmentClipboardIcon height={16} width={16} color="white" />
|
|
|
|
{isJoiningProject ? "Joining..." : "Click to join"}
|
|
|
|
</PrimaryButton>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|