hotfix for the bin duplication in the bin actions of the bin page

This commit is contained in:
csawatzky 2025-08-22 13:35:27 -06:00
parent e313fd10ae
commit 27c69c3e55
2 changed files with 75 additions and 3 deletions

View file

@ -24,7 +24,7 @@ import RemoveSelfFromObject from "user/RemoveSelfFromObject";
import ShareObject from "user/ShareObject"; import ShareObject from "user/ShareObject";
import { isOffline } from "utils/environment"; import { isOffline } from "utils/environment";
import ObjectTeams from "teams/ObjectTeams"; import ObjectTeams from "teams/ObjectTeams";
// import BinDuplication from "./BinDuplication"; import BinDuplication from "./BinDuplication";
import BinsIcon from "products/Bindapt/BinsIcon"; import BinsIcon from "products/Bindapt/BinsIcon";
import HelpIcon from "@mui/icons-material/Help"; import HelpIcon from "@mui/icons-material/Help";
import BinSensors from "./BinSensors"; import BinSensors from "./BinSensors";
@ -269,14 +269,14 @@ export default function BinActions(props: Props) {
closeDialogCallback={() => setOpenState({ ...openState, users: false })} closeDialogCallback={() => setOpenState({ ...openState, users: false })}
refreshCallback={refreshCallback} refreshCallback={refreshCallback}
/> />
{/* <BinDuplication <BinDuplication
open={openState.duplication} open={openState.duplication}
closeDialog={() => { closeDialog={() => {
setOpenState({ ...openState, duplication: false }); setOpenState({ ...openState, duplication: false });
}} }}
bin={bin} bin={bin}
refreshCallback={refreshCallback} refreshCallback={refreshCallback}
/> */} />
<RemoveSelfFromObject <RemoveSelfFromObject
scope={binScope(key)} scope={binScope(key)}
label={label} label={label}

View file

@ -0,0 +1,72 @@
import {
Button,
DialogActions,
DialogContent,
DialogTitle,
TextField,
Typography
} from "@mui/material";
import ResponsiveDialog from "common/ResponsiveDialog";
import { Bin } from "models";
import { useBinAPI, useSnackbar } from "providers";
import { useEffect, useState } from "react";
interface Props {
open: boolean;
bin: Bin;
closeDialog: () => void;
refreshCallback: () => void;
}
export default function BinDuplication(props: Props) {
const { open, bin, closeDialog, refreshCallback } = props;
const [binDupName, setBinDupName] = useState("(copy of) " + bin.name());
const binAPI = useBinAPI();
const { openSnack } = useSnackbar();
useEffect(() => {
setBinDupName("(copy of) " + bin.name());
}, [bin]);
const duplicate = () => {
let settings = bin.settings;
settings.name = binDupName;
binAPI
.addBin(settings)
.then(resp => {
openSnack("Successfully duplicated bin");
})
.catch(err => {
openSnack("Failed to duplicate bin");
});
refreshCallback();
closeDialog();
};
return (
<ResponsiveDialog open={open} onClose={closeDialog}>
<DialogTitle>Create Duplicate Bin</DialogTitle>
<DialogContent>
<Typography>
This will create a new bin with the same settings as {bin.name()}.
</Typography>
<TextField
id={"duplicateName"}
fullWidth
margin="normal"
label="Name of Copy"
value={binDupName}
onChange={e => setBinDupName(e.target.value)}
/>
</DialogContent>
<DialogActions>
<Button onClick={closeDialog} style={{ color: "red" }}>
Cancel
</Button>
<Button onClick={duplicate} color="primary">
Confirm
</Button>
</DialogActions>
</ResponsiveDialog>
);
}