2023-06-26 10:07:12 +00:00
|
|
|
"use client";
|
|
|
|
|
|
2023-02-13 13:46:56 +00:00
|
|
|
import { FC, useState } from "react";
|
|
|
|
|
// import Link from "next/link";
|
|
|
|
|
import {
|
|
|
|
|
Grid,
|
|
|
|
|
Button,
|
|
|
|
|
Dialog,
|
|
|
|
|
DialogActions,
|
|
|
|
|
DialogContent,
|
|
|
|
|
TextField,
|
|
|
|
|
} from "@mui/material";
|
|
|
|
|
import { useTranslate } from "react-polyglot";
|
2023-07-11 13:48:05 +00:00
|
|
|
import { useAppContext } from "app/_components/AppProvider";
|
2023-02-13 13:46:56 +00:00
|
|
|
import { VisualizationDetail } from "./VisualizationDetail";
|
|
|
|
|
|
|
|
|
|
interface VisualizationDetailDialogProps {
|
|
|
|
|
id: string;
|
|
|
|
|
title: string;
|
|
|
|
|
description: string;
|
|
|
|
|
url: string;
|
|
|
|
|
closeDialog: any;
|
|
|
|
|
editing: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const VisualizationDetailDialog: FC<VisualizationDetailDialogProps> = ({
|
|
|
|
|
id,
|
|
|
|
|
title,
|
|
|
|
|
description,
|
|
|
|
|
url,
|
|
|
|
|
closeDialog,
|
|
|
|
|
editing,
|
|
|
|
|
}) => {
|
|
|
|
|
const t = useTranslate();
|
|
|
|
|
const [editedTitle, setEditedTitle] = useState(title);
|
|
|
|
|
const [editedDescription, setEditedDescription] = useState(description);
|
|
|
|
|
const {
|
|
|
|
|
colors: { leafcutterElectricBlue, leafcutterLightBlue, white, almostBlack },
|
|
|
|
|
query,
|
|
|
|
|
} = useAppContext();
|
|
|
|
|
|
|
|
|
|
const deleteAndClose = async () => {
|
|
|
|
|
await fetch(`/api/visualizations/delete`, {
|
|
|
|
|
method: "POST",
|
|
|
|
|
headers: {
|
|
|
|
|
Accept: "application/json",
|
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify({ id }),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
closeDialog();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const saveAndClose = async () => {
|
|
|
|
|
const updateParams = {
|
|
|
|
|
id,
|
|
|
|
|
title: editedTitle,
|
|
|
|
|
description: editedDescription,
|
|
|
|
|
query,
|
|
|
|
|
};
|
|
|
|
|
await fetch(`/api/visualizations/update`, {
|
|
|
|
|
method: "POST",
|
|
|
|
|
headers: {
|
|
|
|
|
Accept: "application/json",
|
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify(updateParams),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
closeDialog();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const buttonStyles = {
|
|
|
|
|
fontSize: 14,
|
|
|
|
|
borderRadius: 500,
|
|
|
|
|
color: white,
|
|
|
|
|
backgroundColor: leafcutterElectricBlue,
|
|
|
|
|
fontWeight: "bold",
|
|
|
|
|
textTransform: "uppercase",
|
|
|
|
|
pl: 3,
|
|
|
|
|
pr: 3,
|
|
|
|
|
":hover": {
|
|
|
|
|
backgroundColor: leafcutterLightBlue,
|
|
|
|
|
color: almostBlack,
|
|
|
|
|
opacity: 0.8,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Dialog open maxWidth="xl">
|
|
|
|
|
<DialogContent sx={{ minWidth: 800 }}>
|
|
|
|
|
{editing && (
|
|
|
|
|
<Grid direction="column" container rowGap={2} sx={{ mb: 3 }}>
|
|
|
|
|
<Grid item>
|
|
|
|
|
<TextField
|
|
|
|
|
value={editedTitle}
|
|
|
|
|
onChange={(e) => setEditedTitle(e.target.value)}
|
|
|
|
|
label={t("title")}
|
|
|
|
|
size="small"
|
|
|
|
|
fullWidth
|
|
|
|
|
/>
|
|
|
|
|
</Grid>
|
|
|
|
|
<Grid>
|
|
|
|
|
<TextField
|
|
|
|
|
value={editedDescription}
|
|
|
|
|
onChange={(e) => setEditedDescription(e.target.value)}
|
|
|
|
|
label={t("description")}
|
|
|
|
|
size="small"
|
|
|
|
|
fullWidth
|
|
|
|
|
/>
|
|
|
|
|
</Grid>
|
|
|
|
|
</Grid>
|
|
|
|
|
)}
|
|
|
|
|
<VisualizationDetail
|
|
|
|
|
id={id}
|
|
|
|
|
title={title}
|
|
|
|
|
description={description}
|
|
|
|
|
url={url}
|
|
|
|
|
editing={editing}
|
|
|
|
|
/>
|
|
|
|
|
</DialogContent>
|
|
|
|
|
<DialogActions sx={{ p: 2.5, pt: 0 }}>
|
|
|
|
|
<Grid container direction="row-reverse" justifyContent="space-between">
|
|
|
|
|
{!editing && (
|
|
|
|
|
<Grid item>
|
|
|
|
|
<Button sx={buttonStyles} onClick={closeDialog} size="small">
|
|
|
|
|
{t("done")}
|
|
|
|
|
</Button>
|
|
|
|
|
</Grid>
|
|
|
|
|
)}
|
2023-03-31 08:34:35 +02:00
|
|
|
{!editing && (
|
|
|
|
|
<Grid item>
|
|
|
|
|
<Button sx={buttonStyles} onClick={deleteAndClose} size="small">
|
|
|
|
|
{t("delete")}
|
|
|
|
|
</Button>
|
|
|
|
|
</Grid>
|
|
|
|
|
)}
|
2023-02-13 13:46:56 +00:00
|
|
|
{editing && (
|
|
|
|
|
<Grid item>
|
|
|
|
|
<Button sx={buttonStyles} onClick={saveAndClose} size="small">
|
|
|
|
|
{t("save")}
|
|
|
|
|
</Button>
|
|
|
|
|
</Grid>
|
|
|
|
|
)}
|
|
|
|
|
{editing && (
|
|
|
|
|
<Grid item>
|
|
|
|
|
<Button sx={buttonStyles} onClick={deleteAndClose} size="small">
|
|
|
|
|
{t("cancel")}
|
|
|
|
|
</Button>
|
|
|
|
|
</Grid>
|
|
|
|
|
)}
|
|
|
|
|
</Grid>
|
|
|
|
|
</DialogActions>
|
|
|
|
|
</Dialog>
|
|
|
|
|
);
|
|
|
|
|
};
|