Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pages/dashboard/admin/+Page.tsx

    rb6e1b3c r5af32f0  
    1919import BuildCard from '../../../components/BuildCard';
    2020import BuildDetailsDialog from '../../../components/BuildDetailsDialog';
    21 import DeleteIcon from "@mui/icons-material/Delete";
    22 import {onDeleteBuild} from "../user/userDashboard.telefunc";
    2321
    2422export default function AdminDashboard() {
     
    2624    const [loading, setLoading] = useState(true);
    2725    const [selectedBuildId, setSelectedBuildId] = useState<number | null>(null);
    28     const [deleteDialog, setDeleteDialog] = useState<{ open: boolean, buildId: number | null, buildName: string }>({ open: false, buildId: null, buildName: '' });
    29     const [deleteLoading, setDeleteLoading] = useState(false);
    30 
     26
     27    // Build approval dialog state
    3128    const [buildApprovalDialog, setBuildApprovalDialog] = useState<{
    3229        open: boolean,
     
    110107        } catch (e) {
    111108            alert("Failed to update suggestion");
    112         }
    113     };
    114 
    115     const openDeleteDialog = (buildId: number, buildName: string) => {
    116         setDeleteDialog({ open: true, buildId, buildName });
    117     };
    118 
    119     const handleDelete = async () => {
    120         if (!deleteDialog.buildId) return;
    121         setDeleteLoading(true);
    122         try {
    123             await onDeleteBuild({buildId: deleteDialog.buildId});
    124             setDeleteDialog({ open: false, buildId: null, buildName: '' });
    125             loadData(); // refresh na user i favorite builds
    126             setSelectedBuildId(null);
    127         } catch (e) {
    128             alert("Failed to delete build");
    129         } finally {
    130             setDeleteLoading(false);
    131109        }
    132110    };
     
    275253                                    <Grid container spacing={2}>
    276254                                        {data.userBuilds.slice(0, 4).map((build: any) => (
    277                                             <Grid item xs={12} sm={6} md={4} key={build.id}>
    278                                                 <Box sx={{ position: 'relative' }}>
    279                                                     <BuildCard
    280                                                         build={build}
    281                                                         onClick={() => setSelectedBuildId(build.id)}
    282                                                     />
    283                                                     <Box sx={{ mt: 1, display: 'flex', justifyContent: 'center' }}>
    284                                                         <Button
    285                                                             variant="outlined"
    286                                                             color="error"
    287                                                             size="small"
    288                                                             startIcon={<DeleteIcon />}
    289                                                             onClick={(e) => {
    290                                                                 e.stopPropagation();
    291                                                                 openDeleteDialog(build.id, build.name);
    292                                                             }}
    293                                                             sx={{ width: '100%' }}
    294                                                         >
    295                                                             Delete
    296                                                         </Button>
    297                                                     </Box>
    298                                                 </Box>
     255                                            <Grid item xs={12} md={3} key={build.id}>
     256                                                <BuildCard
     257                                                    build={build}
     258                                                    onClick={() => setSelectedBuildId(build.id)}
     259                                                />
    299260                                            </Grid>
    300261                                        ))}
     
    368329            </Dialog>
    369330
    370             <Dialog open={deleteDialog.open} onClose={() => setDeleteDialog({ open: false, buildId: null, buildName: '' })}>
    371                 <DialogTitle>Delete Build</DialogTitle>
    372                 <DialogContent>
    373                     <Typography variant="h6" gutterBottom>{deleteDialog.buildName}</Typography>
    374                     <Typography color="text.secondary">
    375                         Are you sure you want to permanently delete this build? This action cannot be undone.
    376                     </Typography>
    377                 </DialogContent>
    378                 <DialogActions>
    379                     <Button
    380                         onClick={() => setDeleteDialog({ open: false, buildId: null, buildName: '' })}
    381                         disabled={deleteLoading}
    382                     >
    383                         Cancel
    384                     </Button>
    385                     <Button
    386                         onClick={handleDelete}
    387                         variant="contained"
    388                         color="error"
    389                         disabled={deleteLoading}
    390                         startIcon={deleteLoading ? <CircularProgress size={20} /> : <DeleteIcon />}
    391                     >
    392                         {deleteLoading ? 'Deleting...' : 'Delete Build'}
    393                     </Button>
    394                 </DialogActions>
    395             </Dialog>
    396 
    397331            <BuildDetailsDialog
    398332                open={!!selectedBuildId}
     
    401335                onClose={() => setSelectedBuildId(null)}
    402336                onClone={() => alert("Clone disabled in admin view")}
    403                 isDashboardView={true}
    404337            />
    405338        </Container>
Note: See TracChangeset for help on using the changeset viewer.