Skip to content

Commit

Permalink
fix: mutate projects list after joining (#1944)
Browse files Browse the repository at this point in the history
Co-authored-by: Aaryan Khandelwal <aaryan610@Aaryans-MacBook-Pro.local>
  • Loading branch information
aaryan610 and Aaryan Khandelwal committed Aug 23, 2023
1 parent a8fdd42 commit 2d14069
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
3 changes: 2 additions & 1 deletion apps/app/components/project/join-project-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const JoinProjectModal: React.FC<TJoinProjectModalProps> = ({ onClose, on

const handleJoin = () => {
setIsJoiningLoading(true);

onJoin()
.then(() => {
setIsJoiningLoading(false);
Expand Down Expand Up @@ -59,7 +60,7 @@ export const JoinProjectModal: React.FC<TJoinProjectModalProps> = ({ onClose, on
leaveFrom="opacity-100 translate-y-0 sm:scale-100"
leaveTo="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
>
<Dialog.Panel className="relative transform overflow-hidden rounded-lg bg-custom-background-80 px-5 py-8 text-left shadow-xl transition-all sm:w-full sm:max-w-xl sm:p-6">
<Dialog.Panel className="relative transform overflow-hidden rounded-lg bg-custom-background-100 border border-custom-border-300 px-5 py-8 text-left shadow-xl transition-all sm:w-full sm:max-w-xl sm:p-6">
<div className="space-y-5">
<Dialog.Title
as="h3"
Expand Down
4 changes: 2 additions & 2 deletions apps/app/components/project/sidebar-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const ProjectSidebarList: FC = () => {

const { projects: allProjects } = useProjects();

const joinedProjects = allProjects?.filter((p) => p.sort_order);
const joinedProjects = allProjects?.filter((p) => p.is_member);
const favoriteProjects = allProjects?.filter((p) => p.is_favorite);

const orderedJoinedProjects: IProject[] | undefined = joinedProjects
Expand Down Expand Up @@ -201,7 +201,7 @@ export const ProjectSidebarList: FC = () => {
key={project.id}
draggableId={project.id}
index={index}
isDragDisabled={project.sort_order === null}
isDragDisabled={!project.is_member}
>
{(provided, snapshot) => (
<div ref={provided.innerRef} {...provided.draggableProps}>
Expand Down
12 changes: 11 additions & 1 deletion apps/app/pages/[workspaceSlug]/projects/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import type { NextPage } from "next";
import { PROJECT_MEMBERS } from "constants/fetch-keys";
// helper
import { truncateText } from "helpers/string.helper";
// types
import { IProject } from "types";

const ProjectsPage: NextPage = () => {
// router
Expand All @@ -39,7 +41,7 @@ const ProjectsPage: NextPage = () => {
const { user } = useUserAuth();
// context data
const { activeWorkspace } = useWorkspaces();
const { projects } = useProjects();
const { projects, mutateProjects } = useProjects();
// states
const [deleteProject, setDeleteProject] = useState<string | null>(null);
const [selectedProjectToJoin, setSelectedProjectToJoin] = useState<string | null>(null);
Expand Down Expand Up @@ -101,6 +103,14 @@ const ProjectsPage: NextPage = () => {
})
.then(async () => {
mutate(PROJECT_MEMBERS(project.id));
mutateProjects<IProject[]>(
(prevData) =>
(prevData ?? []).map((p) => ({
...p,
is_member: p.id === project.id ? true : p.is_member,
})),
false
);
setSelectedProjectToJoin(null);
})
.catch(() => {
Expand Down

1 comment on commit 2d14069

@vercel
Copy link

@vercel vercel bot commented on 2d14069 Aug 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

plane-dev – ./apps/app

plane-dev-plane.vercel.app
plane-dev-git-develop-plane.vercel.app
plane-dev.vercel.app

Please sign in to comment.