Skip to content

Commit

Permalink
Correct website regrex
Browse files Browse the repository at this point in the history
  • Loading branch information
vontell committed Jun 23, 2024
1 parent 57da4d6 commit 0d19902
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 14 deletions.
4 changes: 3 additions & 1 deletion src/components/AddResourceModal/AddBathroom/PageOne.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import MyLocationIcon from '@mui/icons-material/MyLocation';

import { isMobile } from 'react-device-detect';

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 @@ -192,7 +194,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 { isMobile } from 'react-device-detect';

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

const PageOne = ({
// state values and handlers for the textfields
onDrop,
Expand Down Expand Up @@ -263,7 +265,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 { isMobile } from 'react-device-detect';

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 @@ -241,7 +243,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/AddWaterTap/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 { isMobile } from 'react-device-detect';

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 @@ -253,7 +255,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'
);
13 changes: 3 additions & 10 deletions src/components/Toolbar/Toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
toggleResourceType,
toggleResourceMenu
} from '../../actions/actions';
import selectFilteredResource from '../../selectors/waterSelectors';
import styles from './Toolbar.module.scss';

import {
Expand Down Expand Up @@ -128,16 +129,7 @@ function Toolbar(props) {
// NOTE: This was left as an acceptable scenario for now,
// as it is difficult for a user to do this reliably due to the popup of the location panel.
// This may be reproducible on Desktop.
let data;

switch (props.resourceType) {
case WATER_RESOURCE_TYPE:
data = props?.allResources;
break;
// TODO(vontell): Filter based on requested type
default:
data = props?.allResources;
}
let data = props.filteredResources;

const closest = getClosest(data, {
lat: props.userLocation.lat,
Expand Down Expand Up @@ -394,6 +386,7 @@ function Toolbar(props) {
const mapStateToProps = state => ({
resourceType: state.filterMarkers.resourceType,
allResources: state.filterMarkers.allResources,
filteredResources: selectFilteredResource(state),
userLocation: state.filterMarkers.userLocation,
toolbarModal: state.filterMarkers.toolbarModal,
isResourceMenuShown: state.filterMarkers.isResourceMenuShown
Expand Down

0 comments on commit 0d19902

Please sign in to comment.