Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: mutate sidebar projects list after joining #1944

Merged
merged 1 commit into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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