feat: delete/reset application image via ui
Co-authored-by: Jannis Mattheis <contact@jmattheis.de>
This commit is contained in:
parent
4bc42d2c1d
commit
970302106b
|
|
@ -39,6 +39,17 @@ export class AppStore extends BaseStore<IApplication> {
|
||||||
this.snack('Application image updated');
|
this.snack('Application image updated');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public async deleteImage(id: number): Promise<void> {
|
||||||
|
try {
|
||||||
|
await axios.delete(`${config.get('url')}application/${id}/image`);
|
||||||
|
await this.refresh();
|
||||||
|
this.snack('Application image deleted');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error deleting application image:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public update = async (
|
public update = async (
|
||||||
id: number,
|
id: number,
|
||||||
name: string,
|
name: string,
|
||||||
|
|
|
||||||
|
|
@ -22,11 +22,35 @@ import {IApplication} from '../types';
|
||||||
import {LastUsedCell} from '../common/LastUsedCell';
|
import {LastUsedCell} from '../common/LastUsedCell';
|
||||||
import {useStores} from '../stores';
|
import {useStores} from '../stores';
|
||||||
import {observer} from 'mobx-react-lite';
|
import {observer} from 'mobx-react-lite';
|
||||||
|
import {makeStyles} from 'tss-react/mui';
|
||||||
|
import {ButtonBase, Tooltip} from '@mui/material';
|
||||||
|
|
||||||
|
const useStyles = makeStyles()((theme) => ({
|
||||||
|
imageContainer: {
|
||||||
|
'&::after': {
|
||||||
|
content: '"×"',
|
||||||
|
position: 'absolute',
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
width: 40,
|
||||||
|
height: 40,
|
||||||
|
background: theme.palette.error.main,
|
||||||
|
color: theme.palette.getContrastText(theme.palette.error.main),
|
||||||
|
fontSize: 40,
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
opacity: 0,
|
||||||
|
},
|
||||||
|
'&:hover::after': {opacity: 1},
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
const Applications = observer(() => {
|
const Applications = observer(() => {
|
||||||
const {appStore} = useStores();
|
const {appStore} = useStores();
|
||||||
const apps = appStore.getItems();
|
const apps = appStore.getItems();
|
||||||
const [toDeleteApp, setToDeleteApp] = useState<IApplication>();
|
const [toDeleteApp, setToDeleteApp] = useState<IApplication>();
|
||||||
|
const [toDeleteImage, setToDeleteImage] = useState<IApplication>();
|
||||||
const [toUpdateApp, setToUpdateApp] = useState<IApplication>();
|
const [toUpdateApp, setToUpdateApp] = useState<IApplication>();
|
||||||
const [createDialog, setCreateDialog] = useState<boolean>(false);
|
const [createDialog, setCreateDialog] = useState<boolean>(false);
|
||||||
|
|
||||||
|
|
@ -93,6 +117,7 @@ const Applications = observer(() => {
|
||||||
value={app.token}
|
value={app.token}
|
||||||
lastUsed={app.lastUsed}
|
lastUsed={app.lastUsed}
|
||||||
fUpload={() => handleImageUploadClick(app.id)}
|
fUpload={() => handleImageUploadClick(app.id)}
|
||||||
|
fDeleteImage={() => setToDeleteImage(app)}
|
||||||
fDelete={() => setToDeleteApp(app)}
|
fDelete={() => setToDeleteApp(app)}
|
||||||
fEdit={() => setToUpdateApp(app)}
|
fEdit={() => setToUpdateApp(app)}
|
||||||
noDelete={app.internal}
|
noDelete={app.internal}
|
||||||
|
|
@ -133,6 +158,14 @@ const Applications = observer(() => {
|
||||||
fOnSubmit={() => appStore.remove(toDeleteApp.id)}
|
fOnSubmit={() => appStore.remove(toDeleteApp.id)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
{toDeleteImage != null && (
|
||||||
|
<ConfirmDialog
|
||||||
|
title="Confirm Delete Image"
|
||||||
|
text={'Delete image for ' + toDeleteImage.name + '?'}
|
||||||
|
fClose={() => setToDeleteImage(undefined)}
|
||||||
|
fOnSubmit={() => appStore.deleteImage(toDeleteImage.id)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</DefaultPage>
|
</DefaultPage>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
@ -145,6 +178,7 @@ interface IRowProps {
|
||||||
defaultPriority: number;
|
defaultPriority: number;
|
||||||
lastUsed: string | null;
|
lastUsed: string | null;
|
||||||
fUpload: VoidFunction;
|
fUpload: VoidFunction;
|
||||||
|
fDeleteImage: VoidFunction;
|
||||||
image: string;
|
image: string;
|
||||||
fDelete: VoidFunction;
|
fDelete: VoidFunction;
|
||||||
fEdit: VoidFunction;
|
fEdit: VoidFunction;
|
||||||
|
|
@ -159,14 +193,25 @@ const Row = ({
|
||||||
lastUsed,
|
lastUsed,
|
||||||
fDelete,
|
fDelete,
|
||||||
fUpload,
|
fUpload,
|
||||||
|
fDeleteImage,
|
||||||
image,
|
image,
|
||||||
fEdit,
|
fEdit,
|
||||||
}: IRowProps) => {
|
}: IRowProps) => {
|
||||||
|
const {classes} = useStyles();
|
||||||
return (
|
return (
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell padding="normal">
|
<TableCell padding="normal">
|
||||||
<div style={{display: 'flex'}}>
|
<div style={{display: 'flex'}}>
|
||||||
<img src={config.get('url') + image} alt="app logo" width="40" height="40" />
|
<Tooltip title="Delete image" placement="top" arrow>
|
||||||
|
<ButtonBase className={classes.imageContainer} onClick={fDeleteImage}>
|
||||||
|
<img
|
||||||
|
src={config.get('url') + image}
|
||||||
|
alt="app logo"
|
||||||
|
width="40"
|
||||||
|
height="40"
|
||||||
|
/>
|
||||||
|
</ButtonBase>
|
||||||
|
</Tooltip>
|
||||||
<IconButton onClick={fUpload} style={{height: 40}}>
|
<IconButton onClick={fUpload} style={{height: 40}}>
|
||||||
<CloudUpload />
|
<CloudUpload />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue