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

#127 adding cancel button #213

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
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
11 changes: 11 additions & 0 deletions src/components/ProtestForm/ProtestForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { validateLatLng, isValidUrl } from '../../utils';
import { fetchNearbyProtests } from '../../api';
import L from 'leaflet';
import DateTimeList from '../DateTimeList';
import { useHistory } from 'react-router-dom';

const protestMarker = new L.Icon({
iconUrl: '/icons/fist.svg',
Expand All @@ -25,6 +26,7 @@ function ProtestForm({
editMode = null,
isAdmin,
}) {
const history = useHistory();
const coordinatesUpdater = useCallback(() => {
let initialState = [31.7749837, 35.219797];
if (validateLatLng(initialCoords)) initialState = initialCoords;
Expand Down Expand Up @@ -84,6 +86,11 @@ function ProtestForm({
nearbyProtests();
}, [coordinatesUpdater]);

const onCancel = () => {
if (window.confirm('המידע שהזנת לא יישמר. לחזור אחורה?')) {
history.goBack();
}
};
const onSubmit = async (params) => {
if (!editMode && !params.streetAddress) {
alert('אנא הזינו את כתובת ההפגנה');
Expand Down Expand Up @@ -275,6 +282,10 @@ function ProtestForm({
)}
</>
)}
<br />
<Button type="button" onClick={onCancel} color="tomato">
ביטול
</Button>
</ProtestFormWrapper>
);
}
Expand Down