From 8d453fd9afa4a728cefa3f92613d3de5a21290b0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 20 Apr 2026 18:02:48 +0000 Subject: [PATCH 1/4] refactor: unify eligible voter count source and clean up common smells Agent-Logs-Url: https://github.com/NTHU-SA/Voting-System/sessions/b318b56e-a85a-4c80-8b1e-74ce50bfb31c Co-authored-by: l7wei <87221670+l7wei@users.noreply.github.com> --- Dockerfile | 6 +- app/admin/activities/[id]/page.tsx | 14 +- .../activities/[id]/verification/page.tsx | 6 +- .../_components/ActivityFormFields.tsx | 2 +- .../_components/CandidateFormFields.tsx | 2 +- .../_components/OptionFormSection.tsx | 29 +-- .../_components/ViceCandidateSection.tsx | 4 +- .../activities/_components/useOptionForm.ts | 14 +- app/admin/settings/page.tsx | 58 +++--- app/api/activities/[id]/route.ts | 33 ++-- app/api/activities/[id]/voters/route.ts | 9 +- app/api/mock/authorize/page.tsx | 24 +-- app/api/mock/resource/route.ts | 2 +- app/api/votes/route.ts | 3 +- app/layout.tsx | 4 +- app/login/page.tsx | 2 +- app/verify/page.tsx | 10 +- app/vote/[id]/completion/page.tsx | 142 +++++++-------- app/vote/[id]/page.tsx | 104 ++++++----- app/vote/certificate/page.tsx | 11 +- components/ActivityStatusBadge.tsx | 4 +- components/Header.tsx | 170 +++++++++--------- components/LoginModal.tsx | 11 +- components/MarkdownRenderer.tsx | 26 +-- components/ui/card.tsx | 8 +- components/ui/loader.tsx | 8 +- lib/activityVoterService.ts | 5 + lib/statisticsService.ts | 4 +- 28 files changed, 372 insertions(+), 343 deletions(-) create mode 100644 lib/activityVoterService.ts diff --git a/Dockerfile b/Dockerfile index c0ab8e4..66db484 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,13 +25,11 @@ WORKDIR /app ENV NODE_ENV=production ENV NEXT_TELEMETRY_DISABLED=1 -RUN addgroup --system --gid 1001 nodejs -RUN adduser --system --uid 1001 nextjs +RUN addgroup --system --gid 1001 nodejs && adduser --system --uid 1001 nextjs COPY --from=builder /app/public ./public -RUN mkdir .next -RUN chown nextjs:nodejs .next +RUN mkdir .next && chown nextjs:nodejs .next COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static diff --git a/app/admin/activities/[id]/page.tsx b/app/admin/activities/[id]/page.tsx index 441c1f7..1debbb6 100644 --- a/app/admin/activities/[id]/page.tsx +++ b/app/admin/activities/[id]/page.tsx @@ -365,13 +365,13 @@ function ActivityDetailPageContent() { body: formData, }); const data = await response.json(); - if (!data.success) { - setError(data.error || "上傳選民名冊失敗"); - } else { + if (data.success) { setSuccessMessage(`選民名冊上傳成功,共 ${data.data.eligible_voters_count} 人`); setVoterCsvFile(null); await fetchVoterStats(); await refetch(); + } else { + setError(data.error || "上傳選民名冊失敗"); } } catch (err) { console.error("Error uploading voter list:", err); @@ -670,9 +670,11 @@ function ActivityDetailPageContent() { )} - {option.vice && - option.vice.map((vice, viceIndex) => ( -
@@ -176,5 +180,4 @@ export function OptionFormSection({
);
}
-// Export the hook for external use
-export { useOptionForm };
+export { useOptionForm } from "./useOptionForm";
diff --git a/app/admin/activities/_components/ViceCandidateSection.tsx b/app/admin/activities/_components/ViceCandidateSection.tsx
index adbdaca..0288677 100644
--- a/app/admin/activities/_components/ViceCandidateSection.tsx
+++ b/app/admin/activities/_components/ViceCandidateSection.tsx
@@ -17,12 +17,12 @@ export function ViceCandidateSection({
onAddVice,
onRemoveVice,
onViceChange,
-}: ViceCandidateSectionProps) {
+}: Readonly