Changeset b6e1b3c for pages/dashboard


Ignore:
Timestamp:
12/29/25 02:32:48 (6 months ago)
Author:
Mihail <mihail2.naumov@…>
Branches:
main
Children:
f46bf5c
Parents:
3870834
Message:

Added delete button and still fixing naming problem with build creation

Location:
pages/dashboard
Files:
2 edited

Legend:

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

    r3870834 rb6e1b3c  
    1919import BuildCard from '../../../components/BuildCard';
    2020import BuildDetailsDialog from '../../../components/BuildDetailsDialog';
     21import DeleteIcon from "@mui/icons-material/Delete";
     22import {onDeleteBuild} from "../user/userDashboard.telefunc";
    2123
    2224export default function AdminDashboard() {
     
    2426    const [loading, setLoading] = useState(true);
    2527    const [selectedBuildId, setSelectedBuildId] = useState<number | null>(null);
    26 
    27     // Build approval dialog state
     28    const [deleteDialog, setDeleteDialog] = useState<{ open: boolean, buildId: number | null, buildName: string }>({ open: false, buildId: null, buildName: '' });
     29    const [deleteLoading, setDeleteLoading] = useState(false);
     30
    2831    const [buildApprovalDialog, setBuildApprovalDialog] = useState<{
    2932        open: boolean,
     
    107110        } catch (e) {
    108111            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);
    109131        }
    110132    };
     
    253275                                    <Grid container spacing={2}>
    254276                                        {data.userBuilds.slice(0, 4).map((build: any) => (
    255                                             <Grid item xs={12} md={3} key={build.id}>
    256                                                 <BuildCard
    257                                                     build={build}
    258                                                     onClick={() => setSelectedBuildId(build.id)}
    259                                                 />
     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>
    260299                                            </Grid>
    261300                                        ))}
     
    329368            </Dialog>
    330369
     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
    331397            <BuildDetailsDialog
    332398                open={!!selectedBuildId}
     
    335401                onClose={() => setSelectedBuildId(null)}
    336402                onClone={() => alert("Clone disabled in admin view")}
     403                isDashboardView={true}
    337404            />
    338405        </Container>
  • pages/dashboard/user/+Page.tsx

    r3870834 rb6e1b3c  
    1717} from '@mui/material';
    1818import CloseIcon from '@mui/icons-material/Close';
     19import DeleteIcon from '@mui/icons-material/Delete';
    1920
    2021import PersonIcon from '@mui/icons-material/Person';
     
    3839    const [loading, setLoading] = useState(true);
    3940    const [error, setError] = useState<string | null>(null);
    40 
    4141    const [openMyBuildsDialog, setOpenMyBuildsDialog] = useState(false);
    4242    const [openFavoritesDialog, setOpenFavoritesDialog] = useState(false);
    43 
    4443    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);
    4546
    4647    const loadData = () => {
     
    6162    }, []);
    6263
    63     const handleDelete = async (buildId: number) => {
    64         if (!confirm("Are you sure you want to delete this build?")) return;
     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);
    6571        try {
    66             await onDeleteBuild({buildId});
    67             loadData();
     72            await onDeleteBuild({buildId: deleteDialog.buildId});
     73            setDeleteDialog({ open: false, buildId: null, buildName: '' });
     74            loadData(); // refresh na user i favorite builds
    6875            setSelectedBuildId(null);
    6976        } catch (e) {
    7077            alert("Failed to delete build");
     78        } finally {
     79            setDeleteLoading(false);
    7180        }
    7281    };
     
    8695                                                                                        variant="h6">{error}</Typography><Button
    8796        href="/auth/login" variant="contained">Login</Button></Container>;
    88     // console.log("Current User ID passed to dialog:", data?.user?.id);
    8997
    9098    return (
     
    150158                        <Grid item xs={12}>
    151159                            <Paper elevation={3} sx={{p: 3, minHeight: '300px', bgcolor: '#1e1e1e'}}>
    152 
    153160                                <Box sx={{
    154161                                    display: 'flex',
     
    185192                                        {data.userBuilds.slice(0, 4).map((build: any) => (
    186193                                            <Grid item xs={12} sm={6} md={4} key={build.id}>
    187                                                 <BuildCard
    188                                                     build={build}
    189                                                     onClick={() => setSelectedBuildId(build.id)}
    190                                                 />
     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>
    191215                                            </Grid>
    192216                                        ))}
     
    208232                                    {data.userBuilds.map((build: any) => (
    209233                                        <Grid item xs={12} sm={6} md={4} key={build.id}>
    210                                             <BuildCard
    211                                                 build={build}
    212                                                 onClick={() => {
    213                                                     setOpenMyBuildsDialog(false);
    214                                                     setSelectedBuildId(build.id);
    215                                                 }}
    216                                             />
     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>
    217258                                        </Grid>
    218259                                    ))}
     
    252293                        </Dialog>
    253294
     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
    254322                    </Grid>
    255323                </Grid>
     
    265333                }}
    266334                onClone={handleCloneWrapper}
     335                isDashboardView={true}
    267336            />
    268337        </Container>
Note: See TracChangeset for help on using the changeset viewer.