-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
react/kiezradar: add limitation alert
- Loading branch information
1 parent
70d11fb
commit 0bc4699
Showing
5 changed files
with
187 additions
and
164 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## Added | ||
|
||
- Added kiezradar 5 limit exceeded alert |
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 |
---|---|---|
@@ -1,59 +1,31 @@ | ||
import React, { useEffect, useState } from 'react' | ||
import React from 'react' | ||
import django from 'django' | ||
import { useParams } from 'react-router-dom' | ||
import Kiezradar from './Kiezradar' | ||
import Loading from './Loading' | ||
import { alert as Alert } from 'adhocracy4' | ||
|
||
const editText = django.gettext('Edit') | ||
const errorKiezText = django.gettext('Failed to fetch Kiez') | ||
const errorText = django.gettext('Error') | ||
|
||
export default function EditKiezradar (props) { | ||
export default function EditKiezradar ({ kiezradars, ...props }) { | ||
const { id } = useParams() | ||
const [kiezradar, setKiezradar] = useState([]) | ||
const [loading, setLoading] = useState(false) | ||
const [error, setError] = useState(null) | ||
|
||
useEffect(() => { | ||
const fetchKiezradar = async () => { | ||
try { | ||
setLoading(true) | ||
setError(null) | ||
|
||
const response = await fetch(props.apiUrl + id) | ||
|
||
if (!response.ok) { | ||
throw new Error(errorKiezText) | ||
} | ||
const kiezradar = kiezradars?.find( | ||
(kiezradar) => kiezradar.id === parseInt(id, 10) | ||
) | ||
|
||
const data = await response.json() | ||
setKiezradar(data) | ||
} catch (err) { | ||
setError(err.message) | ||
} finally { | ||
setLoading(false) | ||
} | ||
} | ||
fetchKiezradar() | ||
}, []) | ||
if (!kiezradar) { | ||
return ( | ||
<div className="kiezradar__error"> | ||
<Alert type="danger" message={errorText + ': ' + errorKiezText} /> | ||
</div> | ||
) | ||
} | ||
|
||
return ( | ||
<div aria-live="polite"> | ||
{loading | ||
? <Loading /> | ||
: error | ||
? ( | ||
<div className="kiezradar__error"> | ||
<Alert type="danger" message={errorText + ': ' + error} /> | ||
</div> | ||
) | ||
: ( | ||
<> | ||
<h2>{editText + ' ' + kiezradar.name}</h2> | ||
<Kiezradar {...props} kiezradar={kiezradar} /> | ||
</> | ||
)} | ||
</div> | ||
<> | ||
<h2>{editText + ' ' + kiezradar.name}</h2> | ||
<Kiezradar {...props} kiezradar={kiezradar} /> | ||
</> | ||
) | ||
} |
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
Oops, something went wrong.