Skip to content
This repository has been archived by the owner on Dec 16, 2024. It is now read-only.

Commit

Permalink
feat: implements survey-unsubmit-list page
Browse files Browse the repository at this point in the history
  • Loading branch information
jspark2000 committed Mar 14, 2024
1 parent dc4754f commit e1188f7
Show file tree
Hide file tree
Showing 11 changed files with 160 additions and 32 deletions.
45 changes: 39 additions & 6 deletions backend/prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
AccountStatus,
RosterStatus,
RosterType,
ScheduleType
ScheduleType,
AttendanceLocation
} from '@prisma/client'
import { hash } from 'argon2'

Expand Down Expand Up @@ -268,29 +269,34 @@ const seedingDatabase = async () => {
{
scheduleId: 1,
rosterId: 1,
response: 'Present'
response: 'Present',
location: AttendanceLocation.Seoul
},
{
scheduleId: 1,
rosterId: 2,
response: 'Present'
response: 'Present',
location: AttendanceLocation.Seoul
},
{
scheduleId: 1,
rosterId: 3,
response: 'Present'
response: 'Present',
location: AttendanceLocation.Seoul
},
{
scheduleId: 1,
rosterId: 5,
response: 'Tardy',
reason: '수업'
reason: '수업',
location: AttendanceLocation.Suwon
},
{
scheduleId: 1,
rosterId: 6,
response: 'Tardy',
reason: '수업'
reason: '수업',
location: AttendanceLocation.Suwon
},
{
scheduleId: 1,
Expand All @@ -314,6 +320,33 @@ const seedingDatabase = async () => {
await prisma.attendance.createMany({
data: attendances
})

const surveyTargets: Prisma.SurveyTargetCreateManyInput[] = [
{
surveyGroupId: 2,
rosterId: 1
},
{
surveyGroupId: 2,
rosterId: 2
},
{
surveyGroupId: 2,
rosterId: 3
},
{
surveyGroupId: 2,
rosterId: 4
},
{
surveyGroupId: 2,
rosterId: 5
}
]

await prisma.surveyTarget.createMany({
data: surveyTargets
})
}

const main = async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ export default async function SurveyGroupCardSection() {
return <Badge color={BadgeColor.indigo} content="시작전" />
}

const isClosedSurvey = (surveyGroup: SurveyGroupListItem) => {
const now = new Date()
return (
now <= new Date(surveyGroup.startedAt) ||
now >= new Date(surveyGroup.endedAt)
)
}

return (
<>
<h1 className="text-xl font-bold">출석조사 목록</h1>
Expand All @@ -48,27 +56,27 @@ export default async function SurveyGroupCardSection() {
시작:{' '}
<LocalTime
utc={surveyGroup.startedAt}
format="YYYY-MM-DD A HH:mm"
format="YYYY-MM-DD ddd HH:mm"
/>
</p>
<p>
마감:{' '}
<LocalTime
utc={surveyGroup.endedAt}
format="YYYY-MM-DD A HH:mm"
format="YYYY-MM-DD ddd HH:mm"
/>
</p>
</div>
</CardContent>
<CardFooter>
<Link href={`/survey/${surveyGroup.id}`}>
<Button
disabled={
new Date() <= new Date(surveyGroup.startedAt) ||
new Date() >= new Date(surveyGroup.endedAt)
}
size="sm"
>
<Link
href={
isClosedSurvey(surveyGroup)
? '#'
: `/survey/${surveyGroup.id}`
}
>
<Button disabled={isClosedSurvey(surveyGroup)} size="sm">
제출하러가기
</Button>
</Link>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import type { ColumnDef } from '@tanstack/react-table'

export default function UserListTable({ users }: { users: UserListItem[] }) {
const columns: ColumnDef<UserListItem>[] = [
{
accessorKey: 'id',
header: 'ID'
},
{
accessorKey: 'username',
header: '아이디'
Expand Down Expand Up @@ -38,7 +34,7 @@ export default function UserListTable({ users }: { users: UserListItem[] }) {
return (
<LocalTime
utc={row.getValue('lastLogin')}
format="YYYY-MM-DD A hh:mm:ss"
format="YYYY-MM-DD ddd HH:mm:ss"
/>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import Badge, { BadgeColor } from '@/components/Badge'
import { DataTable } from '@/components/DataTable'
import { AttendanceStatus, RosterType } from '@/lib/enums'
import { AttendanceLocation, AttendanceStatus, RosterType } from '@/lib/enums'
import type { AttendanceListItem } from '@/lib/types/attendance'
import type { RosterListItem } from '@/lib/types/roster'
import type { ColumnDef } from '@tanstack/react-table'
Expand Down Expand Up @@ -39,6 +39,19 @@ export default function AthleteAttendanceListTable({
}
}

const renderAttendanceLocation = (attendance: AttendanceListItem) => {
if (attendance.response === AttendanceStatus.Absence) return

switch (attendance.location) {
case AttendanceLocation.Seoul:
return <Badge color={BadgeColor.purple} content="명륜" />
case AttendanceLocation.Suwon:
return <Badge color={BadgeColor.indigo} content="율전" />
default:
return <Badge color={BadgeColor.gray} content="통합" />
}
}

const renderAthleteType = (roster: RosterListItem) => {
if (roster.registerYear === new Date().getFullYear()) {
return <Badge color={BadgeColor.yellow} content="신입생" />
Expand All @@ -47,10 +60,6 @@ export default function AthleteAttendanceListTable({
}

const columns: ColumnDef<AttendanceListItem>[] = [
{
accessorKey: 'id',
header: 'ID'
},
{
id: 'rosterProfile',
header: '이름',
Expand Down Expand Up @@ -92,6 +101,15 @@ export default function AthleteAttendanceListTable({
return renderAthletePosition(attendance.Roster)
}
},
{
accessorKey: 'location',
header: '위치',
cell: ({ row }) => {
const attendance = row.original

return renderAttendanceLocation(attendance)
}
},
{
id: 'type',
header: '구분',
Expand All @@ -112,7 +130,7 @@ export default function AthleteAttendanceListTable({
},
{
accessorKey: 'reason',
header: '불참사유'
header: '사유'
}
]

Expand Down
2 changes: 0 additions & 2 deletions frontend/src/app/console/schedule/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ export default async function AttendanceStatisticPage({
searchTerm
)

console.log(attendanceList)

return (
<main className="mx-auto flex w-full flex-grow flex-col items-center justify-start">
<div className="mt-4 flex w-full items-center justify-between px-4 text-left sm:px-6">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { DataTable } from '@/components/DataTable'
import type { UnsubmitRosterListItem } from '@/lib/types/roster'
import type { ColumnDef } from '@tanstack/react-table'

export default function SurveyUnsubmitListTable({
rosters
}: {
rosters: UnsubmitRosterListItem[]
}) {
const columns: ColumnDef<UnsubmitRosterListItem>[] = [
{
accessorKey: 'name',
header: '이름'
},
{
accessorKey: 'admissionYear',
header: '학번'
}
]

return <DataTable columns={columns} data={rosters} />
}
28 changes: 28 additions & 0 deletions frontend/src/app/console/survey/[id]/unsubmit/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Button } from '@/components/ui/button'
import { getSurveyUnsubmits } from '@/lib/actions'
import Link from 'next/link'
import SurveyUnsubmitListTable from './_components/SurveyUnsubmitListTable'

export default async function SurveyUnsubmitPage({
params
}: {
params: {
id: number
}
}) {
const surveyUnsubmitList = await getSurveyUnsubmits(params.id)

return (
<main className="mx-auto flex w-full flex-grow flex-col items-center justify-start">
<div className="mt-4 flex w-full items-center justify-between px-4 text-left sm:px-6">
<h1 className="text-base font-bold sm:text-xl">미응답자 명단</h1>
<Link href="/console/survey">
<Button variant="outline">목록으로</Button>
</Link>
</div>
<div className="flex w-full flex-grow flex-col gap-5 py-4 sm:px-6">
<SurveyUnsubmitListTable rosters={surveyUnsubmitList.rosters} />
</div>
</main>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import type { SurveyGroupListItem } from '@/lib/types/survey'
import type { ColumnDef } from '@tanstack/react-table'
import { MoreHorizontal } from 'lucide-react'
import Link from 'next/link'
import { useState } from 'react'
import DeleteSurveyGroupForm from './DeleteSurveyGroupForm'
import UpdateSurveyGroupForm from './UpdateSurveyGroupForm'
Expand Down Expand Up @@ -85,7 +86,7 @@ export default function SurveyGroupListTable({
cell: ({ row }) => {
return (
<LocalTime
format="YYYY-MM-DD A hh:mm:ss"
format="YYYY-MM-DD ddd hh:mm:ss"
utc={row.getValue('startedAt')}
/>
)
Expand All @@ -97,7 +98,7 @@ export default function SurveyGroupListTable({
cell: ({ row }) => {
return (
<LocalTime
format="YYYY-MM-DD A hh:mm:ss"
format="YYYY-MM-DD ddd hh:mm:ss"
utc={row.getValue('endedAt')}
/>
)
Expand Down Expand Up @@ -127,6 +128,12 @@ export default function SurveyGroupListTable({
<DropdownMenuContent align="end">
<DropdownMenuLabel>메뉴</DropdownMenuLabel>
<DropdownMenuSeparator />
<DropdownMenuItem>
<Link href={`/console/survey/${surveyGroup.id}/unsubmit`}>
미응답자 확인
</Link>
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem onClick={() => handleUpdateClick(surveyGroup)}>
수정
</DropdownMenuItem>
Expand Down
9 changes: 8 additions & 1 deletion frontend/src/lib/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import type { ScheduleList, ScheduleListItem } from './types/schedule'
import type {
SurveyGroupList,
SurveyGroupListItem,
SurveyGroupWithSchedules
SurveyGroupWithSchedules,
SurveyUnsubmitList
} from './types/survey'
import type { UserList, UserProfile } from './types/user'
import { PAGINATION_LIMIT_DEFAULT } from './vars'
Expand Down Expand Up @@ -73,3 +74,9 @@ export const getAttendances = async (
`/attendances?scheduleId=${scheduleId}&page=${page}&rosterType=${rosterType}&searchTerm=${searchTerm}&limit=${PAGINATION_LIMIT_DEFAULT}`
)
}

export const getSurveyUnsubmits = async (surveyGroupId: number) => {
return await fetcher.get<SurveyUnsubmitList>(
`/surveys/groups/${surveyGroupId}/unsubmits`
)
}
6 changes: 6 additions & 0 deletions frontend/src/lib/types/roster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@ export interface RosterList {
total: number
rosters: RosterListItem[]
}

export interface UnsubmitRosterListItem {
name: string
admissionYear: number
profileImageUrl?: string
}
5 changes: 5 additions & 0 deletions frontend/src/lib/types/survey.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { UnsubmitRosterListItem } from './roster'
import type { Schedule } from './schedule'

type SurveyGroupBasic = {
Expand All @@ -19,3 +20,7 @@ export interface SurveyGroupWithSchedules {
surveyGroup: SurveyGroupBasic
schedules: Schedule[]
}

export interface SurveyUnsubmitList {
rosters: UnsubmitRosterListItem[]
}

0 comments on commit e1188f7

Please sign in to comment.