Ignore:
File:
1 edited

Legend:

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

    rb6e1b3c re599341  
    1717} from '@mui/material';
    1818import CloseIcon from '@mui/icons-material/Close';
    19 import DeleteIcon from '@mui/icons-material/Delete';
    2019
    2120import PersonIcon from '@mui/icons-material/Person';
     
    3938    const [loading, setLoading] = useState(true);
    4039    const [error, setError] = useState<string | null>(null);
     40
    4141    const [openMyBuildsDialog, setOpenMyBuildsDialog] = useState(false);
    4242    const [openFavoritesDialog, setOpenFavoritesDialog] = useState(false);
     43
    4344    const [selectedBuildId, setSelectedBuildId] = useState<number | null>(null);
    44     const [deleteDialog, setDeleteDialog] = useState<{ open: boolean, buildId: number | null, buildName: string }>({ open: false, buildId: null, buildName: '' });
    45     const [deleteLoading, setDeleteLoading] = useState(false);
    4645
    4746    const loadData = () => {
     
    6261    }, []);
    6362
    64     const openDeleteDialog = (buildId: number, buildName: string) => {
    65         setDeleteDialog({ open: true, buildId, buildName });
    66     };
    67 
    68     const handleDelete = async () => {
    69         if (!deleteDialog.buildId) return;
    70         setDeleteLoading(true);
     63    const handleDelete = async (buildId: number) => {
     64        if (!confirm("Are you sure you want to delete this build?")) return;
    7165        try {
    72             await onDeleteBuild({buildId: deleteDialog.buildId});
    73             setDeleteDialog({ open: false, buildId: null, buildName: '' });
    74             loadData(); // refresh na user i favorite builds
     66            await onDeleteBuild({buildId});
     67            loadData();
    7568            setSelectedBuildId(null);
    7669        } catch (e) {
    7770            alert("Failed to delete build");
    78         } finally {
    79             setDeleteLoading(false);
    8071        }
    8172    };
     
    9586                                                                                        variant="h6">{error}</Typography><Button
    9687        href="/auth/login" variant="contained">Login</Button></Container>;
     88    // console.log("Current User ID passed to dialog:", data?.user?.id);
    9789
    9890    return (
     
    158150                        <Grid item xs={12}>
    159151                            <Paper elevation={3} sx={{p: 3, minHeight: '300px', bgcolor: '#1e1e1e'}}>
     152
    160153                                <Box sx={{
    161154                                    display: 'flex',
     
    192185                                        {data.userBuilds.slice(0, 4).map((build: any) => (
    193186                                            <Grid item xs={12} sm={6} md={4} key={build.id}>
    194                                                 <Box sx={{ position: 'relative' }}>
    195                                                     <BuildCard
    196                                                         build={build}
    197                                                         onClick={() => setSelectedBuildId(build.id)}
    198                                                     />
    199                                                     <Box sx={{ mt: 1, display: 'flex', justifyContent: 'center' }}>
    200                                                         <Button
    201                                                             variant="outlined"
    202                                                             color="error"
    203                                                             size="small"
    204                                                             startIcon={<DeleteIcon />}
    205                                                             onClick={(e) => {
    206                                                                 e.stopPropagation();
    207                                                                 openDeleteDialog(build.id, build.name);
    208                                                             }}
    209                                                             sx={{ width: '100%' }}
    210                                                         >
    211                                                             Delete
    212                                                         </Button>
    213                                                     </Box>
    214                                                 </Box>
     187                                                <BuildCard
     188                                                    build={build}
     189                                                    onClick={() => setSelectedBuildId(build.id)}
     190                                                />
    215191                                            </Grid>
    216192                                        ))}
     
    232208                                    {data.userBuilds.map((build: any) => (
    233209                                        <Grid item xs={12} sm={6} md={4} key={build.id}>
    234                                             <Box sx={{ position: 'relative' }}>
    235                                                 <BuildCard
    236                                                     build={build}
    237                                                     onClick={() => {
    238                                                         setOpenMyBuildsDialog(false);
    239                                                         setSelectedBuildId(build.id);
    240                                                     }}
    241                                                 />
    242                                                 <Box sx={{ mt: 1, display: 'flex', justifyContent: 'center' }}>
    243                                                     <Button
    244                                                         variant="outlined"
    245                                                         color="error"
    246                                                         size="small"
    247                                                         startIcon={<DeleteIcon />}
    248                                                         onClick={(e) => {
    249                                                             e.stopPropagation();
    250                                                             openDeleteDialog(build.id, build.name);
    251                                                         }}
    252                                                         sx={{ width: '100%' }}
    253                                                     >
    254                                                         Delete
    255                                                     </Button>
    256                                                 </Box>
    257                                             </Box>
     210                                            <BuildCard
     211                                                build={build}
     212                                                onClick={() => {
     213                                                    setOpenMyBuildsDialog(false);
     214                                                    setSelectedBuildId(build.id);
     215                                                }}
     216                                            />
    258217                                        </Grid>
    259218                                    ))}
     
    293252                        </Dialog>
    294253
    295                         <Dialog open={deleteDialog.open} onClose={() => setDeleteDialog({ open: false, buildId: null, buildName: '' })}>
    296                             <DialogTitle>Delete Build</DialogTitle>
    297                             <DialogContent>
    298                                 <Typography variant="h6" gutterBottom>{deleteDialog.buildName}</Typography>
    299                                 <Typography color="text.secondary">
    300                                     Are you sure you want to permanently delete this build? This action cannot be undone.
    301                                 </Typography>
    302                             </DialogContent>
    303                             <DialogActions>
    304                                 <Button
    305                                     onClick={() => setDeleteDialog({ open: false, buildId: null, buildName: '' })}
    306                                     disabled={deleteLoading}
    307                                 >
    308                                     Cancel
    309                                 </Button>
    310                                 <Button
    311                                     onClick={handleDelete}
    312                                     variant="contained"
    313                                     color="error"
    314                                     disabled={deleteLoading}
    315                                     startIcon={deleteLoading ? <CircularProgress size={20} /> : <DeleteIcon />}
    316                                 >
    317                                     {deleteLoading ? 'Deleting...' : 'Delete Build'}
    318                                 </Button>
    319                             </DialogActions>
    320                         </Dialog>
    321 
    322254                    </Grid>
    323255                </Grid>
     
    333265                }}
    334266                onClone={handleCloneWrapper}
    335                 isDashboardView={true}
    336267            />
    337268        </Container>
Note: See TracChangeset for help on using the changeset viewer.