Skip to content
Snippets Groups Projects
Verified Commit 8e874b06 authored by Marte Fossum's avatar Marte Fossum
Browse files

Reload guests when period changed

parent 3ac692f5
No related branches found
No related tags found
1 merge request!376Reload guests when period changed
Pipeline #179245 passed
......@@ -30,9 +30,14 @@ import useOus from '../../../../hooks/useOus'
interface GuestRoleInfoProps {
guest: Guest
reloadGuest: () => void
reloadGuests: () => void
}
const endPeriodPost = (id: string, data: { end_date: Date }) => {
const endPeriodPost = (
id: string,
data: { end_date: Date },
reloadGuests: () => void
) => {
const payload = {
end_date: format(data.end_date as Date, 'yyyy-MM-dd'),
}
......@@ -48,6 +53,7 @@ const endPeriodPost = (id: string, data: { end_date: Date }) => {
.then((result) => {
if (result !== null) {
console.log('result', result)
reloadGuests()
}
})
.catch((error) => {
......@@ -107,6 +113,7 @@ const TableContainer = styled(TableContainerMui)({
export default function GuestRoleInfo({
guest,
reloadGuest,
reloadGuests,
}: GuestRoleInfoProps) {
const { pid, id } = useParams<GuestRoleInfoParams>()
const { ous } = useOus()
......@@ -145,7 +152,7 @@ export default function GuestRoleInfo({
setBadEndDate(true)
} else {
role.end_date = newEndDate
endPeriodPost(role_id, { end_date: newEndDate })
endPeriodPost(role_id, { end_date: newEndDate }, reloadGuests)
// Go back to guest overview page
navigate(`/sponsor/guest/${guest.pid}`, {
state: {
......@@ -192,6 +199,7 @@ export default function GuestRoleInfo({
console.log('result', result)
}
// Reload the guest so that the information on the overview page is updated
reloadGuests()
reloadGuest()
// A submit does not clear the dirty state, so resetting values in the form
// to the values just submitted to clear the dirty-flag
......
......@@ -66,7 +66,11 @@ function GuestRoutes({ reloadGuests }: GuestRoutesProps) {
<Route
path="/roles/:id"
element={
<GuestRoleInfo guest={guestInfo} reloadGuest={reloadGuestInfo} />
<GuestRoleInfo
guest={guestInfo}
reloadGuest={reloadGuestInfo}
reloadGuests={reloadGuests}
/>
}
/>
<Route
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment