Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
majkshkurti committed Sep 19, 2023
1 parent 1f81366 commit 868810f
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 7 deletions.
2 changes: 1 addition & 1 deletion apps/web/components/dashboard/home/BlogSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const blogPosts: BlogPost[] = [
url: "https://plan4better.de/en/posts/2023-08-01-parking/",
},
{
title: "GOAT as a cross-stakeholder planning platform in the MRN",
title: "Green Spaces in Urban Areas: The Key to Resilient Cities",
date: "May 30, 2023",
thumbnail:
"https://plan4better.de/images/blog/green-spaces-resilient-cities/thumbnail.webp",
Expand Down
5 changes: 5 additions & 0 deletions apps/web/components/dashboard/home/SectionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ const SectionCard = (props: SectionCard) => {
<DeleteContentModal
open={isDeleteDialogOpen}
onClose={() => setIsDeleteDialogOpen(false)}
onDelete={() => {
setIsDeleteDialogOpen(false);
setActiveContent(null);
// show success toast
}}
activeContent={activeContent}
/>
<Card
Expand Down
26 changes: 21 additions & 5 deletions apps/web/components/modals/DeleteContent.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { ActiveCard } from "@/components/dashboard/home/SectionCard";
import { LAYERS_API_BASE_URL, deleteLayer } from "@/lib/api/layers";
import { PROJECTS_API_BASE_URL, deleteProject } from "@/lib/api/projects";
import {
Button,
Dialog,
Expand All @@ -8,6 +10,8 @@ import {
DialogTitle,
Typography,
} from "@mui/material";
import { toast } from "react-toastify";
import { mutate } from "swr";

interface DeleteContentDialogProps {
open: boolean;
Expand All @@ -24,7 +28,21 @@ const DeleteContentModal: React.FC<DeleteContentDialogProps> = ({
onDelete,
activeContent,
}) => {
const handleDelete = () => {
const handleDelete = async () => {
try {
if (!activeContent) return;
if (activeContent.type === "layer") {
await deleteLayer(activeContent?.id);
mutate((key) => Array.isArray(key) && key[0] === LAYERS_API_BASE_URL);
} else if (activeContent.type === "project") {
await deleteProject(activeContent?.id);
mutate((key) => Array.isArray(key) && key[0] === PROJECTS_API_BASE_URL);
}
toast.success(`${activeContent?.type} deleted successfully`);
} catch {
toast.error(`Error deleting ${activeContent?.type}`);
}

if (onDelete) onDelete();
};

Expand All @@ -43,10 +61,7 @@ const DeleteContentModal: React.FC<DeleteContentDialogProps> = ({
pb: 2,
}}
>
<Button
onClick={onClose}
variant="text"
>
<Button onClick={onClose} variant="text" sx={{ borderRadius: 0 }}>
<Typography variant="body2" fontWeight="bold" color="inherit">
Cancel
</Typography>
Expand All @@ -56,6 +71,7 @@ const DeleteContentModal: React.FC<DeleteContentDialogProps> = ({
variant="text"
color="error"
disabled={disabled}
sx={{ borderRadius: 0 }}
>
<Typography variant="body2" fontWeight="bold" color="inherit">
Delete
Expand Down
11 changes: 11 additions & 0 deletions apps/web/lib/api/layers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,14 @@ export const useLayers = (queryParams?: GetContentQueryParams) => {
isValidating,
};
};

export const deleteLayer = async (id: string) => {
try {
await fetch(`${LAYERS_API_BASE_URL}/${id}`, {
method: "DELETE",
});
} catch (error) {
console.error(error);
throw Error(`deleteLayer: unable to delete project with id ${id}`);
}
};
1 change: 1 addition & 0 deletions apps/web/lib/api/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ export const deleteProject = async (id: string) => {
throw Error(`deleteProject: unable to delete project with id ${id}`)
}
}

7 changes: 6 additions & 1 deletion apps/web/lib/providers/ToastProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ export default function ToastProvider({ children }: ToastProviderProps) {
return (
<>
{children}
<ToastContainer transition={Zoom} position="top-center" autoClose={2000} />
<ToastContainer
transition={Zoom}
position="top-center"
autoClose={2000}
hideProgressBar
/>
</>
);
}
3 changes: 3 additions & 0 deletions packages/ui/theme/overrides/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ const Button = (theme: Theme) => {
padding: `${theme.spacing(1.875, 6.25)}`,
},
},
dialogBoxRectangle: {
borderRadius: 0,
}
},
},
};
Expand Down

0 comments on commit 868810f

Please sign in to comment.