import MenuIcon from '@mui/icons-material/Menu'; import { Button, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, Divider, Menu, MenuItem } from "@mui/material"; import { Routine } from "@/components/Routines/models/Routine"; import { useDeleteRoutineQuery } from "@/components/Routines/queries"; import { RoutineTemplateForm } from "@/components/Routines/widgets/forms/RoutineTemplateForm"; import React, { useState } from "react"; import { useTranslation } from "react-i18next"; import { Link, useNavigate } from "react-router-dom"; import { makeLink, WgerLink } from "@/core/lib/url"; export enum DialogToOpen { NONE, DELETE_CONFIRMATION, EDIT_TEMPLATE } export const RoutineDetailDropdown = (props: { routine: Routine }) => { const navigate = useNavigate(); const useDeleteQuery = useDeleteRoutineQuery(props.routine.id!); const [t, i18n] = useTranslation(); const [anchorEl, setAnchorEl] = useState(null); const [deleteConfirmationOpen, setConfirmationOpen] = useState(DialogToOpen.NONE); const open = Boolean(anchorEl); const handleClick = (event: React.MouseEvent) => { setAnchorEl(event.currentTarget); }; const handleDelete = () => { setConfirmationOpen(DialogToOpen.DELETE_CONFIRMATION); handleClose(); // Close the dropdown menu }; const handleTemplate = () => { setConfirmationOpen(DialogToOpen.EDIT_TEMPLATE); handleClose(); }; const handleConfirmDelete = async () => { await useDeleteQuery.mutateAsync(); navigate(makeLink(WgerLink.ROUTINE_OVERVIEW, i18n.language)); }; const handleCloseDialogs = () => { setConfirmationOpen(DialogToOpen.NONE); }; const handleClose = () => { setAnchorEl(null); }; /* * Note: this is a workaround. Instead of just using the navigate function we need to * force a reload of the page, otherwise the drag-and-drop doesn't work properly * when loaded from within the django application. This has probably to do with * the way we add the components there. If we find a solution for that one day, * this can be removed. * * See also: https://github.com/wger-project/wger/issues/1943 */ const navigateEdit = () => window.location.href = makeLink( WgerLink.ROUTINE_EDIT, i18n.language, { id: props.routine.id! } ); return (
{t("edit")} Table view {props.routine.isNotTemplate && {t("routines.logsOverview")} } {props.routine.isNotTemplate && {t("routines.statsOverview")} } {t("routines.duplicate")} {t("routines.markAsTemplate")} {t("routines.downloadPdfTable")} {t("routines.downloadPdfLogs")} {t("routines.downloadIcal")} {t("delete")} {t('delete')} {t('deleteConfirmation', { name: props.routine.name })} {t("routines.markAsTemplate")}
); };