Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(j-s): Use lawyer registry from api #17434

Merged
merged 15 commits into from
Jan 17, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add error handling to get single lawyer
oddsson committed Jan 9, 2025
commit fd6946a196974ae6f54a31b9b461f43442e413c7
6 changes: 6 additions & 0 deletions apps/judicial-system/web/messages/Core/errors.ts
Original file line number Diff line number Diff line change
@@ -94,6 +94,12 @@ export const errors = defineMessages({
description:
'Notaður sem villuskilaboð þegar ekki gengur að sækja lögmanna skrá',
},
fetchLawyer: {
id: 'judicial.system.core:errors.fetch_lawyer',
defaultMessage: 'Upp kom villa við að sækja lögmann úr lögmanna skrá',
description:
'Notaður sem villuskilaboð þegar ekki gengur að sækja lögmann úr lögmanna skrá',
},
copyLink: {
id: 'judicial.system.core:errors.copy_link',
defaultMessage: 'Ekki tókst að afrita hlekk',
Original file line number Diff line number Diff line change
@@ -39,6 +39,8 @@ export const useGetLawyer = (
nationalId?: string | null,
shouldFetch?: boolean,
): Lawyer | undefined => {
const { formatMessage } = useIntl()

const fetcher = (url: string): Promise<Lawyer> =>
fetch(url).then((res) => {
if (!res.ok) {
@@ -50,7 +52,7 @@ export const useGetLawyer = (
return res.json()
})

const { data } = useSWR<Lawyer>(
const { data, error } = useSWR<Lawyer>(
nationalId && shouldFetch
? `/api/defender/lawyerRegistry/${nationalId}`
: null,
@@ -63,5 +65,10 @@ export const useGetLawyer = (
},
)

if (error) {
toast.error(formatMessage(errorMessages.fetchLawyer))
return undefined
}

return data
}