This repository has been archived by the owner on Jun 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementert error og loading håndtering
- Loading branch information
1 parent
265c8e5
commit 6eb270e
Showing
3 changed files
with
52 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { fetchToJson } from '../../ducks/api-utils'; | ||
import { FULLFOER_REAKTIVERING_URL, requestConfig } from '../../ducks/api'; | ||
import { Alert, Button } from '@navikt/ds-react'; | ||
import { useState } from 'react'; | ||
import spacing from '../../spacing.module.css'; | ||
|
||
const ReaktiveringsKnapp = () => { | ||
const [showError, setShowError] = useState(false); | ||
const [loading, setLoading] = useState(false); | ||
const fullfoerReaktivering = async () => { | ||
setLoading(true); | ||
setShowError(false); | ||
try { | ||
await fetchToJson(FULLFOER_REAKTIVERING_URL, { | ||
...requestConfig(), | ||
method: 'POST', | ||
}); | ||
window.location.reload(); | ||
} catch (e) { | ||
setShowError(true); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<Button variant="primary" onClick={fullfoerReaktivering} loading={loading}> | ||
Registrer deg som arbeidssøker | ||
</Button> | ||
{showError && ( | ||
<Alert variant={'error'} className={spacing.mt1}> | ||
Noe gikk dessverre galt. Prøv igjen. | ||
</Alert> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default ReaktiveringsKnapp; |