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

Implements the Verification System #458

Merged
merged 12 commits into from
Jul 24, 2024
96 changes: 80 additions & 16 deletions public/testData.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
},
"state": "PA",
"status": "OPERATIONAL",
"verified": false,
"verification": {
"verified": false,
"last_modified": "2024-03-31T00:37:46.004545+00:00",
"verifier": "phlask"
},
"version": 1,
"water": {
"dispenser_type": [
Expand All @@ -44,7 +48,11 @@
},
"state": "PA",
"status": "OPERATIONAL",
"verified": false,
"verification": {
"verified": false,
"last_modified": "2024-03-31T00:37:46.004545+00:00",
"verifier": "phlask"
},
"version": 1,
"water": {
"dispenser_type": [
Expand All @@ -71,7 +79,11 @@
},
"state": "PA",
"status": "OPERATIONAL",
"verified": false,
"verification": {
"verified": false,
"last_modified": "2024-03-31T00:37:46.004545+00:00",
"verifier": "phlask"
},
"version": 1,
"water": {
"dispenser_type": [
Expand All @@ -98,7 +110,11 @@
},
"state": "PA",
"status": "OPERATIONAL",
"verified": false,
"verification": {
"verified": false,
"last_modified": "2024-03-31T00:37:46.004545+00:00",
"verifier": "phlask"
},
"version": 1,
"water": {
"dispenser_type": [
Expand All @@ -125,7 +141,11 @@
},
"state": "PA",
"status": "OPERATIONAL",
"verified": false,
"verification": {
"verified": false,
"last_modified": "2024-03-31T00:37:46.004545+00:00",
"verifier": "phlask"
},
"version": 1,
"water": {
"dispenser_type": [
Expand All @@ -152,7 +172,11 @@
},
"state": "PA",
"status": "OPERATIONAL",
"verified": false,
"verification": {
"verified": false,
"last_modified": "2024-03-31T00:37:46.004545+00:00",
"verifier": "phlask"
},
"version": 1,
"water": {
"dispenser_type": [
Expand All @@ -179,7 +203,11 @@
},
"state": "PA",
"status": "OPERATIONAL",
"verified": false,
"verification": {
"verified": false,
"last_modified": "2024-03-31T00:37:46.004545+00:00",
"verifier": "phlask"
},
"version": 1,
"water": {
"dispenser_type": [
Expand All @@ -206,7 +234,11 @@
},
"state": "PA",
"status": "OPERATIONAL",
"verified": false,
"verification": {
"verified": false,
"last_modified": "2024-03-31T00:37:46.004545+00:00",
"verifier": "phlask"
},
"version": 1,
"water": {
"dispenser_type": [
Expand Down Expand Up @@ -237,7 +269,11 @@
},
"state": "PA",
"status": "OPERATIONAL",
"verified": false,
"verification": {
"verified": false,
"last_modified": "2024-03-31T00:37:46.004545+00:00",
"verifier": "phlask"
},
"version": 1,
"zip_code": "19149"
},
Expand All @@ -263,7 +299,11 @@
},
"state": "PA",
"status": "OPERATIONAL",
"verified": false,
"verification": {
"verified": false,
"last_modified": "2024-03-31T00:37:46.004545+00:00",
"verifier": "phlask"
},
"version": 1,
"zip_code": "19149"
},
Expand All @@ -289,7 +329,11 @@
},
"state": "PA",
"status": "OPERATIONAL",
"verified": false,
"verification": {
"verified": false,
"last_modified": "2024-03-31T00:37:46.004545+00:00",
"verifier": "phlask"
},
"version": 1,
"zip_code": "19149"
},
Expand All @@ -315,7 +359,11 @@
},
"state": "PA",
"status": "OPERATIONAL",
"verified": false,
"verification": {
"verified": false,
"last_modified": "2024-03-31T00:37:46.004545+00:00",
"verifier": "phlask"
},
"version": 1,
"zip_code": "19149"
},
Expand All @@ -341,7 +389,11 @@
},
"state": "PA",
"status": "OPERATIONAL",
"verified": false,
"verification": {
"verified": false,
"last_modified": "2024-03-31T00:37:46.004545+00:00",
"verifier": "phlask"
},
"version": 1,
"zip_code": "19149"
},
Expand All @@ -367,7 +419,11 @@
},
"state": "PA",
"status": "OPERATIONAL",
"verified": false,
"verification": {
"verified": false,
"last_modified": "2024-03-31T00:37:46.004545+00:00",
"verifier": "phlask"
},
"version": 1,
"zip_code": "19149"
},
Expand All @@ -393,7 +449,11 @@
},
"state": "PA",
"status": "OPERATIONAL",
"verified": false,
"verification": {
"verified": false,
"last_modified": "2024-03-31T00:37:46.004545+00:00",
"verifier": "phlask"
},
"version": 1,
"zip_code": "19149"
},
Expand All @@ -419,7 +479,11 @@
},
"state": "PA",
"status": "OPERATIONAL",
"verified": false,
"verification": {
"verified": false,
"last_modified": "2024-03-31T00:37:46.004545+00:00",
"verifier": "phlask"
},
"version": 1,
"zip_code": "19149"
}
Expand Down
10 changes: 9 additions & 1 deletion src/actions/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ export const getResources = createAsyncThunk(
if (process.env.REACT_APP_CYPRESS_TEST) return testData;
const snapshot = await get(ref(database, '/'));
const results = snapshot.val();
return Object.values(results) || [];
return Object.entries(results).map(
([id, resource]) => ({
...resource,
id
})
);
}
);

Expand All @@ -48,6 +53,9 @@ export const pushNewResource = newResource => ({
newResource
});

// Handles the case where an existing resource is updated from the submission form
export const updateExistingResource = createAction('UPDATE_EXISTING_RESOURCE');

export const SET_USER_LOCATION = 'SET_USER_LOCATION';
export const setUserLocation = coords => ({
type: SET_USER_LOCATION,
Expand Down
4 changes: 3 additions & 1 deletion src/components/AddResourceModal/AddBathroom/PageOne.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import MyLocationIcon from '@mui/icons-material/MyLocation';
import useIsMobile from 'hooks/useIsMobile';
import noop from 'utils/noop';

import { WEBSITE_REGEX } from '../utils';

const ENTRY_TYPE = [
{ entryType: 'Open access', explanation: 'Public site, open to all' },
{ entryType: 'Restricted', explanation: 'May not be open to all' },
Expand Down Expand Up @@ -195,7 +197,7 @@ const PageOne = ({
<Controller
rules={{
required: false,
pattern: /^[A-Za-z]{1,}[.]{1}[a-z]{2,3}/
pattern: WEBSITE_REGEX
}}
control={control}
name="website"
Expand Down
4 changes: 3 additions & 1 deletion src/components/AddResourceModal/AddFood/PageOne.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import useIsMobile from 'hooks/useIsMobile';
import noop from 'utils/noop';

import { WEBSITE_REGEX } from '../utils';

const PageOne = ({
// state values and handlers for the textfields
onDrop,
Expand Down Expand Up @@ -265,7 +267,7 @@ const PageOne = ({
<Controller
rules={{
required: false,
pattern: /^[A-Za-z]{1,}[.]{1}[a-z]{2,3}/
pattern: WEBSITE_REGEX
}}
control={control}
name="website"
Expand Down
4 changes: 3 additions & 1 deletion src/components/AddResourceModal/AddForaging/PageOne.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import useIsMobile from 'hooks/useIsMobile';
import noop from 'utils/noop';

import { WEBSITE_REGEX } from '../utils';

const ENTRY_TYPE = [
{ entryType: 'Open access', explanation: 'Public site, open to all' },
{ entryType: 'Restricted', explanation: 'May not be open to all' },
Expand Down Expand Up @@ -243,7 +245,7 @@ const PageOne = ({
<Controller
rules={{
required: false,
pattern: /^[A-Za-z]{1,}[.]{1}[a-z]{2,3}/
pattern: WEBSITE_REGEX
}}
control={control}
name="website"
Expand Down
17 changes: 12 additions & 5 deletions src/components/AddResourceModal/AddResourceModalV2.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import AddBathroom from './AddBathroom/AddBathroom';
import AddForaging from './AddForaging/AddForaging';
import AddWaterTap from './AddWaterTap/AddWaterTap';
import ModalWrapper from './ModalWrapper';
import { getDatabase, ref, push, onValue } from 'firebase/database';
import { getDatabase, ref, push } from 'firebase/database';
import { geocodeByAddress, getLatLng } from 'react-places-autocomplete';
import { pushNewResource, setSelectedPlace } from '../../actions/actions';
import { pushNewResource } from '../../actions/actions';

import {
WATER_RESOURCE_TYPE,
Expand Down Expand Up @@ -251,7 +251,11 @@ export default function AddResourceModalV2(props) {
source: {
type: 'MANUAL'
},
verified: false,
verification: {
last_modified: new Date().toISOString(),
last_modifier: 'phlask_app',
verified: false
},
resource_type: resourceType,
address: values.address,
city: city,
Expand Down Expand Up @@ -350,8 +354,11 @@ export default function AddResourceModalV2(props) {
// TODO(vontell): We probably should not init this here ever time, although it is likely fine.
const app = initializeApp(resourcesConfig);
const database = getDatabase(app);
push(ref(database, '/'), newResource);
dispatch(pushNewResource(newResource));
push(ref(database, '/'), newResource).then(result => {
const id = result._path.pieces[0];
newResource.id = id;
dispatch(pushNewResource(newResource));
});
});
};

Expand Down
4 changes: 3 additions & 1 deletion src/components/AddResourceModal/AddWaterTap/PageOne.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import useIsMobile from 'hooks/useIsMobile';
import noop from 'utils/noop';

import { WEBSITE_REGEX } from '../utils';

const ENTRY_TYPE = [
{ entryType: 'Open access', explanation: 'Public site, open to all' },
{ entryType: 'Restricted', explanation: 'May not be open to all' },
Expand Down Expand Up @@ -256,7 +258,7 @@ const PageOne = ({
<Controller
rules={{
required: false,
pattern: /^[A-Za-z]{1,}[.]{1}[a-z]{2,3}/
pattern: WEBSITE_REGEX
}}
control={control}
name="website"
Expand Down
10 changes: 10 additions & 0 deletions src/components/AddResourceModal/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,13 @@ export const connectToFirebase = (hostname, resourceType) => {
// return firebase.initializeApp(firebaseConfig, "new");
return initializeApp(firebaseConfig, 'new');
};

export const WEBSITE_REGEX = new RegExp(
'^([a-zA-Z]+:\\/\\/)?' + // protocol (optional)
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
'((\\d{1,3}\\.){3}\\d{1,3}))' + // OR IP (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
'(\\#[-a-z\\d_]*)?$', // fragment locator
'i'
);
17 changes: 16 additions & 1 deletion src/components/SelectedTapMobile/SelectedTapDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
FOOD_RESOURCE_TYPE,
FORAGE_RESOURCE_TYPE
} from '../../types/ResourceEntry';
import VerificationButton from 'components/Verification/VerificationButton';

function SelectedTapDetails(props) {
const [pointerPositionY, setPointerPositionY] = useState(0);
Expand All @@ -36,6 +37,10 @@ function SelectedTapDetails(props) {
*/
const resource = props.selectedPlace;

if (resource == null || Object.keys(resource).length === 0) {
return <div></div>;
}

let icon;
switch (resource.resource_type) {
case WATER_RESOURCE_TYPE:
Expand Down Expand Up @@ -153,7 +158,17 @@ function SelectedTapDetails(props) {
{/* Currently the three dot button does nothing */}
</div>
)}
<img src={image} className={styles.locationImage} alt="" />
<div
style={{
width: '100%',
height: '100px',
borderRadius: '8px',
position: 'relative'
}}
>
<img src={image} className={styles.locationImage} alt="" />
<VerificationButton resource={resource} />
</div>
<div className={styles.mainHalfInfo}>
<img
src={icon}
Expand Down
Loading
Loading