Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/admin/cycles/[id]/cycle-dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,15 @@ export function CycleDashboard({
applications={applications}
getApplicationDetails={getApplicationDetails}
settings={defaultSettings}
readOnly={!cycle.isActive}
/>
</TabsContent>

<TabsContent value="nominations">
<NominationsManager
nominations={nominations}
settings={defaultSettings}
readOnly={!cycle.isActive}
/>
</TabsContent>

Expand Down
35 changes: 20 additions & 15 deletions components/AdminDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ interface AdminDashboardProps {
applications: ApplicationWithCount[];
getApplicationDetails: (id: string) => Promise<ApplicationWithNominations | null>;
settings: Settings;
readOnly?: boolean;
}

function getNominationBadgeColor(count: number, requiredNominations: number): "success" | "warning" | "info" | "default" {
Expand All @@ -52,7 +53,7 @@ function getNominationBadgeColor(count: number, requiredNominations: number): "s
return "default"; // Gray for 0-1
}

export default function AdminDashboard({ applications, getApplicationDetails, settings }: AdminDashboardProps) {
export default function AdminDashboard({ applications, getApplicationDetails, settings, readOnly = false }: AdminDashboardProps) {
const [searchTerm, setSearchTerm] = useState('');
const [selectedApplicant, setSelectedApplicant] = useState<ApplicationWithCount | null>(null);
const [applicantDetails, setApplicantDetails] = useState<ApplicationWithNominations | null>(null);
Expand Down Expand Up @@ -417,25 +418,29 @@ export default function AdminDashboard({ applications, getApplicationDetails, se
<Download className="h-4 w-4 mr-2" />
View PDF
</Button>
<Button
variant="destructive"
size="sm"
onClick={handleRemovePdf}
disabled={isRemovingPdf}
>
<Trash2 className="h-4 w-4 mr-2" />
{isRemovingPdf ? 'Removing...' : 'Remove PDF'}
</Button>
{!readOnly && (
<Button
variant="destructive"
size="sm"
onClick={handleRemovePdf}
disabled={isRemovingPdf}
>
<Trash2 className="h-4 w-4 mr-2" />
{isRemovingPdf ? 'Removing...' : 'Remove PDF'}
</Button>
)}
</div>
</div>
</AlertDescription>
</Alert>

<div className="bg-muted p-4 rounded-lg">
<p className="text-sm text-muted-foreground">
To reject this paper nomination, click "Remove PDF" above. The nominee will then be able to collect online nominations or upload a new paper form.
</p>
</div>
{!readOnly && (
<div className="bg-muted p-4 rounded-lg">
<p className="text-sm text-muted-foreground">
To reject this paper nomination, click "Remove PDF" above. The nominee will then be able to collect online nominations or upload a new paper form.
</p>
</div>
)}
</div>
</div>
</>
Expand Down
101 changes: 54 additions & 47 deletions components/NominationsManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type NominationWithCommunity = Nomination & {
interface NominationsManagerProps {
nominations: NominationWithCommunity[];
settings: Settings;
readOnly?: boolean;
}

function getStatusBadge(status: string) {
Expand All @@ -61,7 +62,7 @@ function getConstituencyBadge(nom: NominationWithCommunity) {
return <Badge variant="outline" className="text-xs border-gray-400 dark:border-gray-500">{nom.college}</Badge>;
}

export default function NominationsManager({ nominations: initialNominations, settings }: NominationsManagerProps) {
export default function NominationsManager({ nominations: initialNominations, settings, readOnly = false }: NominationsManagerProps) {
const searchParams = useSearchParams();
const pathname = usePathname();
const isInitialMount = useRef(false);
Expand Down Expand Up @@ -405,7 +406,7 @@ export default function NominationsManager({ nominations: initialNominations, se
</SelectContent>
</Select>

{selectedIds.size > 0 && (
{!readOnly && selectedIds.size > 0 && (
<div className="flex gap-2">
<Button
onClick={handleBulkApprove}
Expand Down Expand Up @@ -438,40 +439,44 @@ export default function NominationsManager({ nominations: initialNominations, se
<Table>
<TableHeader>
<TableRow>
<TableHead className="w-12">
<Checkbox
checked={allSelected}
onCheckedChange={handleSelectAll}
aria-label="Select all"
className={someSelected ? "data-[state=checked]:bg-primary" : ""}
/>
</TableHead>
{!readOnly && (
<TableHead className="w-12">
<Checkbox
checked={allSelected}
onCheckedChange={handleSelectAll}
aria-label="Select all"
className={someSelected ? "data-[state=checked]:bg-primary" : ""}
/>
</TableHead>
)}
<TableHead>Nominee</TableHead>
<TableHead>Nominator</TableHead>
<TableHead>Constituency</TableHead>
<TableHead>Major(s)</TableHead>
<TableHead>Submitted</TableHead>
<TableHead>Status</TableHead>
<TableHead className="text-right">Actions</TableHead>
{!readOnly && <TableHead className="text-right">Actions</TableHead>}
</TableRow>
</TableHeader>
<TableBody>
{filteredNominations.length === 0 ? (
<TableRow>
<TableCell colSpan={8} className="text-center text-muted-foreground py-8">
<TableCell colSpan={readOnly ? 7 : 8} className="text-center text-muted-foreground py-8">
No nominations found
</TableCell>
</TableRow>
) : (
filteredNominations.map((nom) => (
<TableRow key={nom.id}>
<TableCell>
<Checkbox
checked={selectedIds.has(nom.id)}
onCheckedChange={(checked) => handleSelectOne(nom.id, checked as boolean)}
aria-label={`Select ${nom.nominee}`}
/>
</TableCell>
{!readOnly && (
<TableCell>
<Checkbox
checked={selectedIds.has(nom.id)}
onCheckedChange={(checked) => handleSelectOne(nom.id, checked as boolean)}
aria-label={`Select ${nom.nominee}`}
/>
</TableCell>
)}
<TableCell>
<div className="font-medium">{nom.nominee}</div>
</TableCell>
Expand All @@ -489,34 +494,36 @@ export default function NominationsManager({ nominations: initialNominations, se
{new Date(nom.createdAt).toLocaleDateString()}
</TableCell>
<TableCell>{getStatusBadge(nom.status)}</TableCell>
<TableCell className="text-right">
<div className="flex justify-end gap-2">
{nom.status !== 'APPROVED' && (
<Button
size="sm"
onClick={() => handleApprove(nom.id)}
disabled={isProcessing}
variant="outline"
className="border-success text-success hover:bg-success-muted"
>
<CheckCircle className="h-3 w-3 mr-1" />
Approve
</Button>
)}
{nom.status !== 'REJECTED' && (
<Button
size="sm"
onClick={() => handleReject(nom.id)}
disabled={isProcessing}
variant="outline"
className="border-error text-error hover:bg-error-muted"
>
<XCircle className="h-3 w-3 mr-1" />
Reject
</Button>
)}
</div>
</TableCell>
{!readOnly && (
<TableCell className="text-right">
<div className="flex justify-end gap-2">
{nom.status !== 'APPROVED' && (
<Button
size="sm"
onClick={() => handleApprove(nom.id)}
disabled={isProcessing}
variant="outline"
className="border-success text-success hover:bg-success-muted"
>
<CheckCircle className="h-3 w-3 mr-1" />
Approve
</Button>
)}
{nom.status !== 'REJECTED' && (
<Button
size="sm"
onClick={() => handleReject(nom.id)}
disabled={isProcessing}
variant="outline"
className="border-error text-error hover:bg-error-muted"
>
<XCircle className="h-3 w-3 mr-1" />
Reject
</Button>
)}
</div>
</TableCell>
)}
</TableRow>
))
)}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nomination-system/source",
"version": "1.5.0",
"version": "1.5.1",
"license": "MIT",
"scripts": {
"dev": "next dev",
Expand Down
Loading