Skip to content

Commit

Permalink
Add bad password error on contribution form
Browse files Browse the repository at this point in the history
  • Loading branch information
Bo-Duke committed May 3, 2024
1 parent 54ecf89 commit aa9e077
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
5 changes: 1 addition & 4 deletions src/api/postObservation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ async function postObservation(
const json = await res.json();

if (res.status < 200 || res.status > 299) {
const errors = Object.values(json)
.map(err => (Array.isArray(err) ? err[0] : err))
.join('. ');
return { error: true, message: errors };
return { error: true, message: json };
}
return { error: false, message: json };
} catch (error) {
Expand Down
12 changes: 11 additions & 1 deletion src/components/custom-observation-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const CustomObservationForm = ({
const { observationCoordinates } = useMapContext();

const [isLoading, setLoading] = useState(false);
const [serverErrors, setServerErrors] = useState(false);
const [stationsDetails, setStationsDetails] = useState<Station[]>([]);

const [editorState, setEditorState] = useState(() =>
Expand Down Expand Up @@ -93,7 +94,8 @@ const CustomObservationForm = ({
if (!result.error) {
router.push(`/map?${params.toString()}`);
} else {
console.error(result.message);
console.error(result);
setServerErrors(result.message);
}
} else {
const errorMap = validation.errorMap;
Expand Down Expand Up @@ -190,6 +192,14 @@ const CustomObservationForm = ({
</div>
<p className="my-8 text-sm">{t('gdpr')}</p>

{Object.entries(serverErrors).map(([type, message]) => (
<div className="rjf-input-group">
<span className="rjf-error-text">
{type}: {message}
</span>
</div>
))}

<Button className="my-3 flex gap-2" type="submit">
{isLoading && (
<>
Expand Down

0 comments on commit aa9e077

Please sign in to comment.