-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1355 frontend for submitting interview rooms (#1385)
* Create page for room overview * Add table of interview rooms * Create page for creating rooms * Add edit and delete room functionality --------- Co-authored-by: Snorre Sæther <[email protected]>
- Loading branch information
Showing
14 changed files
with
315 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 146 additions & 0 deletions
146
frontend/src/PagesAdmin/RoomAdminPage/CreateInterviewRoomPage/CreateInterviewRoomPage.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { useNavigate, useParams } from 'react-router-dom'; | ||
import { toast } from 'react-toastify'; | ||
import { SamfundetLogoSpinner } from '~/Components'; | ||
import { SamfForm } from '~/Forms/SamfForm'; | ||
import { SamfFormField } from '~/Forms/SamfFormField'; | ||
import { AdminPageLayout } from '~/PagesAdmin/AdminPageLayout/AdminPageLayout'; | ||
import { getInterviewRoom, postInterviewRoom, putInterviewRoom } from '~/api'; | ||
import type { InterviewRoomDto } from '~/dto'; | ||
import { STATUS } from '~/http_status_codes'; | ||
import { KEY } from '~/i18n/constants'; | ||
import { reverse } from '~/named-urls'; | ||
import { ROUTES } from '~/routes'; | ||
|
||
type FormType = { | ||
name: string; | ||
location: string; | ||
start_time: string; | ||
end_time: string; | ||
}; | ||
|
||
export function CreateInterviewRoomPage() { | ||
const { t } = useTranslation(); | ||
const navigate = useNavigate(); | ||
|
||
const { recruitmentId, roomId } = useParams(); | ||
const [showSpinner, setShowSpinner] = useState<boolean>(true); | ||
const [room, setRoom] = useState<Partial<InterviewRoomDto>>(); | ||
|
||
useEffect(() => { | ||
if (roomId) { | ||
getInterviewRoom(roomId) | ||
.then((data) => { | ||
setRoom(data.data); | ||
setShowSpinner(false); | ||
}) | ||
.catch((data) => { | ||
if (data.request.status === STATUS.HTTP_404_NOT_FOUND) { | ||
navigate( | ||
reverse({ | ||
pattern: ROUTES.frontend.admin_recruitment_room_overview, | ||
urlParams: { recruitmentId: recruitmentId }, | ||
}), | ||
{ replace: true }, | ||
); | ||
} | ||
toast.error(t(KEY.common_something_went_wrong)); | ||
}); | ||
} else { | ||
setShowSpinner(false); | ||
} | ||
}, [roomId, recruitmentId, navigate, t]); | ||
|
||
const initialData: Partial<InterviewRoomDto> = { | ||
name: room?.name, | ||
location: room?.location, | ||
start_time: room?.start_time, | ||
end_time: room?.end_time, | ||
}; | ||
|
||
const submitText = roomId ? t(KEY.common_save) : t(KEY.common_create); | ||
|
||
if (showSpinner) { | ||
return ( | ||
<div> | ||
<SamfundetLogoSpinner /> | ||
</div> | ||
); | ||
} | ||
|
||
function handleOnSubmit(data: InterviewRoomDto) { | ||
const updatedRoom = { | ||
...data, | ||
recruitment: recruitmentId, | ||
}; | ||
|
||
if (roomId) { | ||
putInterviewRoom(roomId, updatedRoom) | ||
.then(() => { | ||
toast.success(t(KEY.common_update_successful)); | ||
navigate( | ||
reverse({ | ||
pattern: ROUTES.frontend.admin_recruitment_room_overview, | ||
urlParams: { recruitmentId: recruitmentId }, | ||
}), | ||
); | ||
}) | ||
.catch((error) => { | ||
toast.error(t(KEY.common_something_went_wrong)); | ||
console.error(error); | ||
}); | ||
} else { | ||
postInterviewRoom(updatedRoom) | ||
.then(() => { | ||
navigate( | ||
reverse({ | ||
pattern: ROUTES.frontend.admin_recruitment_room_overview, | ||
urlParams: { recruitmentId: recruitmentId }, | ||
}), | ||
); | ||
toast.success(t(KEY.common_creation_successful)); | ||
}) | ||
.catch((error) => { | ||
toast.error(t(KEY.common_something_went_wrong)); | ||
console.error(error); | ||
}); | ||
} | ||
} | ||
|
||
return ( | ||
<AdminPageLayout title={`${roomId ? t(KEY.common_edit) : t(KEY.common_create)}`} header={true}> | ||
<div> | ||
<SamfForm<FormType> onSubmit={handleOnSubmit} initialData={initialData} submitText={submitText}> | ||
<div> | ||
<SamfFormField<string, FormType> field="name" type="text" label={t(KEY.common_name)} required={true} /> | ||
</div> | ||
<div> | ||
<SamfFormField<string, FormType> | ||
field="location" | ||
type="text" | ||
label={t(KEY.recruitment_interview_location)} | ||
required={true} | ||
/> | ||
</div> | ||
<div> | ||
<SamfFormField<string, FormType> | ||
field="start_time" | ||
type="date_time" | ||
label={t(KEY.start_time)} | ||
required={true} | ||
/> | ||
</div> | ||
<div> | ||
<SamfFormField<string, FormType> | ||
field="end_time" | ||
type="date_time" | ||
label={t(KEY.end_time)} | ||
required={true} | ||
/> | ||
</div> | ||
</SamfForm> | ||
</div> | ||
</AdminPageLayout> | ||
); | ||
} |
1 change: 1 addition & 0 deletions
1
frontend/src/PagesAdmin/RoomAdminPage/CreateInterviewRoomPage/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { CreateInterviewRoomPage } from './CreateInterviewRoomPage'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { useRouteLoaderData } from 'react-router-dom'; | ||
import { toast } from 'react-toastify'; | ||
import { Button, CrudButtons, Table } from '~/Components'; | ||
import { deleteInterviewRoom, getInterviewRoomsForRecruitment } from '~/api'; | ||
import type { InterviewRoomDto } from '~/dto'; | ||
import { useCustomNavigate } from '~/hooks'; | ||
import { KEY } from '~/i18n/constants'; | ||
import { reverse } from '~/named-urls'; | ||
import type { RecruitmentLoader } from '~/router/loaders'; | ||
import { ROUTES } from '~/routes'; | ||
|
||
export function RoomAdminPage() { | ||
const [interviewRooms, setInterviewRooms] = useState<InterviewRoomDto[] | undefined>(); | ||
const data = useRouteLoaderData('recruitment') as RecruitmentLoader | undefined; | ||
const navigate = useCustomNavigate(); | ||
const { t } = useTranslation(); | ||
|
||
useEffect(() => { | ||
if (data?.recruitment?.id) { | ||
getInterviewRoomsForRecruitment(data.recruitment.id.toString()).then((response) => | ||
setInterviewRooms(response.data), | ||
); | ||
} | ||
}, [data?.recruitment?.id]); | ||
|
||
if (!interviewRooms) { | ||
return <p>No rooms found</p>; | ||
} | ||
|
||
const columns = [ | ||
{ content: 'Room Name', sortable: true }, | ||
{ content: 'Location', sortable: true }, | ||
{ content: 'Start Time', sortable: true }, | ||
{ content: 'End Time', sortable: true }, | ||
{ content: 'Recruitment', sortable: true }, | ||
{ content: 'Gang', sortable: true }, | ||
{ content: 'Actions', sortable: false }, | ||
]; | ||
|
||
const tableData = interviewRooms.map((room) => [ | ||
room.name, | ||
room.location, | ||
new Date(room.start_time), | ||
new Date(room.end_time), | ||
room.recruitment, | ||
room.gang !== undefined ? room.gang : 'N/A', | ||
{ | ||
content: ( | ||
<CrudButtons | ||
key={`edit-room-${room.id}`} | ||
onEdit={() => | ||
navigate({ | ||
url: reverse({ | ||
pattern: ROUTES.frontend.admin_recruitment_room_edit, | ||
urlParams: { recruitmentId: data?.recruitment?.id, roomId: room.id.toString() }, | ||
}), | ||
}) | ||
} | ||
onDelete={() => { | ||
deleteInterviewRoom(room.id.toString()).then(() => { | ||
toast.success('Interview room deleted'); | ||
setInterviewRooms(interviewRooms.filter((r) => r.id !== room.id)); | ||
}); | ||
}} | ||
/> | ||
), | ||
}, | ||
]); | ||
|
||
return ( | ||
<> | ||
<Button | ||
link={reverse({ | ||
pattern: ROUTES.frontend.admin_recruitment_room_create, | ||
urlParams: { recruitmentId: data?.recruitment?.id }, | ||
})} | ||
theme="samf" | ||
> | ||
{t(KEY.common_create)} | ||
</Button> | ||
<Table columns={columns} data={tableData} defaultSortColumn={0} /> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { CreateInterviewRoomPage } from './CreateInterviewRoomPage'; | ||
export { RoomAdminPage } from './RoomAdminPage'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.