-
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.
MIJN-9682-Feature/blokkeren-stadspas (#1699)
* added mock route * Added block URL to data * Added conditional button to block stadspassen * Moved logic * fixed tests * TODO comments * remove imports * Refactored out function for use in block pass * Made modal width resemble figma design * semi working version * small refactor * shows geblokkeerd after pas * Fix all stadspassen having the same ID * fix test * Add error alert * Put list of stadspas owners into a table for the 'actief' status * stopped updating whole appstate. Using atom instead * replaced with SWR functionality * Moved hook to hooks file * added mock route * Added block URL to data * Added conditional button to block stadspassen * Moved logic * fixed tests * TODO comments * remove imports * Refactored out function for use in block pass * Made modal width resemble figma design * semi working version * small refactor * shows geblokkeerd after pas * Fix all stadspassen having the same ID * fix test * Add error alert * Put list of stadspas owners into a table for the 'actief' status * stopped updating whole appstate. Using atom instead * replaced with SWR functionality * Moved hook to hooks file * use cache instead of atom, but does not rerender when updating cache * Corrected a type that got changed after a rebase with main * Moved routers next to eachother to make it more readable when you want to see which routers are in use * Refactor some types * Added route to the private stadspas handlers * Added route to openapi docs * Added tests for backend * updated snapshot * Added to test, but broken. Blocked pass won't show up yett * Mijn-9682-Feature - blokkeren stadspas with proper swr (#1708) * Fix types * Fix implementation * Refine types * Refine type * Juggle around references, change name * Change mock server responses (add dynamic props) * Change name * Change http verb * Rename hook * Enable delay * Change markup * FIx type * Add deprecation (boyscout) * Rename * Styling * ADd hack * Fix test * Fix gpass tests * Fix * Addes tests, made helper to create components * Add test for blocked pas --------- Co-authored-by: Tim van Oostrom <[email protected]>
- Loading branch information
1 parent
1ab9a1c
commit d1a504d
Showing
66 changed files
with
1,224 additions
and
349 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { atom, useRecoilState } from 'recoil'; | ||
import useSWRMutation from 'swr/mutation'; | ||
|
||
import { StadspasFrontend } from '../../../server/services/hli/stadspas-types'; | ||
import { useAppStateGetter } from '../../hooks/useAppState'; | ||
|
||
type StadspasActiefByID = { | ||
[id: string]: boolean; | ||
}; | ||
|
||
const stadspasActiefAtom = atom<StadspasActiefByID>({ | ||
key: 'stadspasActief', | ||
default: {}, | ||
}); | ||
|
||
export function useStadspassen() { | ||
const { HLI } = useAppStateGetter(); | ||
const [stadspasActief, setStadspassenActiefStatus] = | ||
useRecoilState(stadspasActiefAtom); | ||
|
||
const stadspassen: StadspasFrontend[] = (HLI.content?.stadspas || []).map( | ||
(pas) => { | ||
const stadspas = { | ||
...pas, | ||
actief: stadspasActief[pas.id] ?? true, | ||
}; | ||
return stadspas; | ||
} | ||
); | ||
|
||
return [stadspassen, setStadspassenActiefStatus] as const; | ||
} | ||
|
||
export function useBlockStadspas(url: string | null, stadspasId: string) { | ||
const setStadspassenActiefStatus = useStadspassen()[1]; | ||
|
||
return useSWRMutation( | ||
url, | ||
async (url) => { | ||
const response = await fetch(url, { | ||
method: 'POST', | ||
credentials: 'include', | ||
}); | ||
|
||
if (!response.ok) { | ||
throw new Error('Request returned with an error'); | ||
} | ||
|
||
setStadspassenActiefStatus((stadspasActiefState) => { | ||
return { ...stadspasActiefState, [stadspasId]: false }; | ||
}); | ||
|
||
return response; | ||
}, | ||
{ revalidate: false, populateCache: false } | ||
); | ||
} |
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.