Skip to content
Snippets Groups Projects
Verified Commit 4b2ce2c3 authored by Andreas Ellewsen's avatar Andreas Ellewsen
Browse files

Simplify guest fetching

parent 049e7c86
No related branches found
No related tags found
1 merge request!204Modify register step form for guests
import { useEffect, useState } from 'react'
import { FetchedGuest, Guest } from 'interfaces'
import { parseIdentity, parseRole } from 'utils'
import { parseIdentity, parseRole, fetchJsonOpts } from 'utils'
const useGuests = () => {
const [guests, setGuests] = useState<Guest[]>([])
const getGuestsInfo = async () => {
try {
const response = await fetch('/api/ui/v1/guests/?format=json')
const jsonResponse = await response.json()
if (response.ok) {
const persons = await jsonResponse
const getGuestsInfo = () =>
fetch('/api/ui/v1/guests/', fetchJsonOpts())
.then((response) => (response.ok ? response.json() : []))
.then((persons) => {
setGuests(
persons.map(
(person: FetchedGuest): Guest => ({
......@@ -28,11 +26,8 @@ const useGuests = () => {
})
)
)
}
} catch (error) {
setGuests([])
}
}
})
.catch(() => setGuests([]))
const reloadGuests = () => {
getGuestsInfo()
......
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