mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
chore: updated project favorites endpoints (#375)
This commit is contained in:
parent
786816ed41
commit
d6badcd9b8
@ -64,7 +64,7 @@ export const ProjectSidebarList: FC = () => {
|
|||||||
workspaceSlug ? PROJECTS_LIST(workspaceSlug as string) : null,
|
workspaceSlug ? PROJECTS_LIST(workspaceSlug as string) : null,
|
||||||
() => (workspaceSlug ? projectService.getProjects(workspaceSlug as string) : null)
|
() => (workspaceSlug ? projectService.getProjects(workspaceSlug as string) : null)
|
||||||
);
|
);
|
||||||
const normalProjects = projects?.filter((p) => !p.is_favourite) ?? [];
|
const normalProjects = projects?.filter((p) => !p.is_favorite) ?? [];
|
||||||
|
|
||||||
const handleCopyText = (projectId: string) => {
|
const handleCopyText = (projectId: string) => {
|
||||||
const originURL =
|
const originURL =
|
||||||
|
@ -46,11 +46,11 @@ export const SingleProjectCard: React.FC<ProjectCardProps> = ({
|
|||||||
project.id
|
project.id
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleAddToFavourites = () => {
|
const handleAddToFavorites = () => {
|
||||||
if (!workspaceSlug) return;
|
if (!workspaceSlug) return;
|
||||||
|
|
||||||
projectService
|
projectService
|
||||||
.addProjectToFavourites(workspaceSlug as string, {
|
.addProjectToFavorites(workspaceSlug as string, {
|
||||||
project: project.id,
|
project: project.id,
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
@ -59,7 +59,7 @@ export const SingleProjectCard: React.FC<ProjectCardProps> = ({
|
|||||||
(prevData) =>
|
(prevData) =>
|
||||||
(prevData ?? []).map((p) => ({
|
(prevData ?? []).map((p) => ({
|
||||||
...p,
|
...p,
|
||||||
is_favourite: p.id === project.id ? true : p.is_favourite,
|
is_favorite: p.id === project.id ? true : p.is_favorite,
|
||||||
})),
|
})),
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
@ -68,30 +68,30 @@ export const SingleProjectCard: React.FC<ProjectCardProps> = ({
|
|||||||
setToastAlert({
|
setToastAlert({
|
||||||
type: "success",
|
type: "success",
|
||||||
title: "Success!",
|
title: "Success!",
|
||||||
message: "Successfully added the project to favourites.",
|
message: "Successfully added the project to favorites.",
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
setToastAlert({
|
setToastAlert({
|
||||||
type: "error",
|
type: "error",
|
||||||
title: "Error!",
|
title: "Error!",
|
||||||
message: "Couldn't remove the project from favourites. Please try again.",
|
message: "Couldn't remove the project from favorites. Please try again.",
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleRemoveFromFavourites = () => {
|
const handleRemoveFromFavorites = () => {
|
||||||
if (!workspaceSlug || !project) return;
|
if (!workspaceSlug || !project) return;
|
||||||
|
|
||||||
projectService
|
projectService
|
||||||
.removeProjectFromFavourites(workspaceSlug as string, project.id)
|
.removeProjectFromFavorites(workspaceSlug as string, project.id)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
mutate<IProject[]>(
|
mutate<IProject[]>(
|
||||||
PROJECTS_LIST(workspaceSlug as string),
|
PROJECTS_LIST(workspaceSlug as string),
|
||||||
(prevData) =>
|
(prevData) =>
|
||||||
(prevData ?? []).map((p) => ({
|
(prevData ?? []).map((p) => ({
|
||||||
...p,
|
...p,
|
||||||
is_favourite: p.id === project.id ? false : p.is_favourite,
|
is_favorite: p.id === project.id ? false : p.is_favorite,
|
||||||
})),
|
})),
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
@ -104,14 +104,14 @@ export const SingleProjectCard: React.FC<ProjectCardProps> = ({
|
|||||||
setToastAlert({
|
setToastAlert({
|
||||||
type: "success",
|
type: "success",
|
||||||
title: "Success!",
|
title: "Success!",
|
||||||
message: "Successfully removed the project from favourites.",
|
message: "Successfully removed the project from favorites.",
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
setToastAlert({
|
setToastAlert({
|
||||||
type: "error",
|
type: "error",
|
||||||
title: "Error!",
|
title: "Error!",
|
||||||
message: "Couldn't remove the project from favourites. Please try again.",
|
message: "Couldn't remove the project from favorites. Please try again.",
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -163,7 +163,7 @@ export const SingleProjectCard: React.FC<ProjectCardProps> = ({
|
|||||||
) : (
|
) : (
|
||||||
<span className="rounded bg-green-600 px-2 py-1 text-xs">Member</span>
|
<span className="rounded bg-green-600 px-2 py-1 text-xs">Member</span>
|
||||||
)}
|
)}
|
||||||
{project.is_favourite && (
|
{project.is_favorite && (
|
||||||
<span className="grid h-6 w-9 place-items-center rounded bg-orange-400">
|
<span className="grid h-6 w-9 place-items-center rounded bg-orange-400">
|
||||||
<StarIcon className="h-3 w-3" />
|
<StarIcon className="h-3 w-3" />
|
||||||
</span>
|
</span>
|
||||||
@ -212,13 +212,13 @@ export const SingleProjectCard: React.FC<ProjectCardProps> = ({
|
|||||||
Delete project
|
Delete project
|
||||||
</CustomMenu.MenuItem>
|
</CustomMenu.MenuItem>
|
||||||
)}
|
)}
|
||||||
{project.is_favourite ? (
|
{project.is_favorite ? (
|
||||||
<CustomMenu.MenuItem onClick={handleRemoveFromFavourites}>
|
<CustomMenu.MenuItem onClick={handleRemoveFromFavorites}>
|
||||||
Remove from favourites
|
Remove from favorites
|
||||||
</CustomMenu.MenuItem>
|
</CustomMenu.MenuItem>
|
||||||
) : (
|
) : (
|
||||||
<CustomMenu.MenuItem onClick={handleAddToFavourites}>
|
<CustomMenu.MenuItem onClick={handleAddToFavorites}>
|
||||||
Add to favourites
|
Add to favorites
|
||||||
</CustomMenu.MenuItem>
|
</CustomMenu.MenuItem>
|
||||||
)}
|
)}
|
||||||
<CustomMenu.MenuItem onClick={handleCopyText}>
|
<CustomMenu.MenuItem onClick={handleCopyText}>
|
||||||
|
@ -258,28 +258,28 @@ class ProjectServices extends APIService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getFavoriteProjects(workspaceSlug: string): Promise<IFavoriteProject[]> {
|
async getFavoriteProjects(workspaceSlug: string): Promise<IFavoriteProject[]> {
|
||||||
return this.get(`/api/workspaces/${workspaceSlug}/user-favourite-projects/`)
|
return this.get(`/api/workspaces/${workspaceSlug}/user-favorite-projects/`)
|
||||||
.then((response) => response?.data)
|
.then((response) => response?.data)
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
throw error?.response?.data;
|
throw error?.response?.data;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async addProjectToFavourites(
|
async addProjectToFavorites(
|
||||||
workspaceSlug: string,
|
workspaceSlug: string,
|
||||||
data: {
|
data: {
|
||||||
project: string;
|
project: string;
|
||||||
}
|
}
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
return this.post(`/api/workspaces/${workspaceSlug}/user-favourite-projects/`, data)
|
return this.post(`/api/workspaces/${workspaceSlug}/user-favorite-projects/`, data)
|
||||||
.then((response) => response?.data)
|
.then((response) => response?.data)
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
throw error?.response?.data;
|
throw error?.response?.data;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async removeProjectFromFavourites(workspaceSlug: string, projectId: string): Promise<any> {
|
async removeProjectFromFavorites(workspaceSlug: string, projectId: string): Promise<any> {
|
||||||
return this.delete(`/api/workspaces/${workspaceSlug}/user-favourite-projects/${projectId}/`)
|
return this.delete(`/api/workspaces/${workspaceSlug}/user-favorite-projects/${projectId}/`)
|
||||||
.then((response) => response?.data)
|
.then((response) => response?.data)
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
throw error?.response?.data;
|
throw error?.response?.data;
|
||||||
|
2
apps/app/types/projects.d.ts
vendored
2
apps/app/types/projects.d.ts
vendored
@ -10,7 +10,7 @@ export interface IProject {
|
|||||||
icon: string;
|
icon: string;
|
||||||
id: string;
|
id: string;
|
||||||
identifier: string;
|
identifier: string;
|
||||||
is_favourite: boolean;
|
is_favorite: boolean;
|
||||||
module_view: boolean;
|
module_view: boolean;
|
||||||
name: string;
|
name: string;
|
||||||
network: number;
|
network: number;
|
||||||
|
Loading…
Reference in New Issue
Block a user