From 748ac438d99d90b13d4bfc4238e06f651b67c77b Mon Sep 17 00:00:00 2001 From: Evan Yang Date: Sun, 8 Oct 2023 23:39:43 -0700 Subject: [PATCH] feat: Validate Google drive, but not sure how to use custom error msg --- client/src/components/data.js | 16 ++-- .../components/manageProjects/editProject.js | 32 +++++--- .../parts/form/ValidatedTextField.js | 81 ++++++++++--------- 3 files changed, 76 insertions(+), 53 deletions(-) diff --git a/client/src/components/data.js b/client/src/components/data.js index c5e7a27b..80212bd4 100644 --- a/client/src/components/data.js +++ b/client/src/components/data.js @@ -12,7 +12,8 @@ export const simpleInputs = [ type: 'textarea', placeholder: 'Enter project description', value: /^[a-zA-Z0-9].{0,250}$/, - errorMessage: 'Description must start with alphanumeric characters, 250 char limit' + errorMessage: + 'Description must start with alphanumeric characters, 250 char limit', }, { label: 'Location', @@ -34,24 +35,27 @@ export const simpleInputs = [ label: 'GitHub URL', name: 'githubUrl', type: 'text', - placeholder: 'htttps://github.com/', + placeholder: 'https://github.com/', }, { label: 'Slack Channel Link', name: 'slackUrl', type: 'text', - placeholder: 'htttps://slack.com/', + placeholder: 'https://slack.com/', }, { label: 'Google Drive URL', name: 'googleDriveUrl', type: 'text', - placeholder: 'htttps://drive.google.com/', + placeholder: 'https://drive.google.com/', + validate: function (value) { + return value.startsWith('https://drive.google.com/'); + }, }, { label: 'HFLA Website URL', name: 'hflaWebsiteUrl', type: 'text', - placeholder: 'htttps://hackforla.org/projects/', + placeholder: 'https://hackforla.org/projects/', }, -]; \ No newline at end of file +]; diff --git a/client/src/components/manageProjects/editProject.js b/client/src/components/manageProjects/editProject.js index 8be19e9a..0530997c 100644 --- a/client/src/components/manageProjects/editProject.js +++ b/client/src/components/manageProjects/editProject.js @@ -99,7 +99,8 @@ const EditProject = ({ setFormData={setFormData} /> - {eventAlert} @@ -161,17 +165,27 @@ const EditProject = ({ function RegularEvent({ event, updateRegularEvent }) { return (
  • -
  • - ) + ); } - - export default EditProject; diff --git a/client/src/components/parts/form/ValidatedTextField.js b/client/src/components/parts/form/ValidatedTextField.js index b6fc6c5b..334a4b7b 100644 --- a/client/src/components/parts/form/ValidatedTextField.js +++ b/client/src/components/parts/form/ValidatedTextField.js @@ -1,5 +1,5 @@ import React from 'react'; -import { Box, Grid, InputLabel, TextField } from "@mui/material"; +import { Box, Grid, InputLabel, TextField } from '@mui/material'; /** * A validated text field component for forms. @@ -26,45 +26,50 @@ function ValidatedTextField({ }) { const registerObj = { ...register(input.name, { - required: `${input.name} is required`, - pattern: - input.name === 'location' - ? locationType === 'remote' - ? { - value: input.value, - message: input.errorMessage, - } - : { - value: input.addressValue, - message: input.addressError, - } - : { value: input.value, message: input.errorMessage }, - } - )} + required: `${input.name} is required`, + pattern: + input.name === 'location' + ? locationType === 'remote' + ? { + value: input.value, + message: input.errorMessage, + } + : { + value: input.addressValue, + message: input.addressError, + } + : { value: input.value, message: input.errorMessage }, + validate: (value) => { + if (input.validate) { + return input.validate(value); + } else return true; + }, + }), + }; return ( - - - - - {input.label} - + + + + + {input.label} + + + {input.name === 'location' && locationRadios} - {input.name === 'location' && locationRadios} - - - + + ); -}; +} -export default ValidatedTextField; \ No newline at end of file +export default ValidatedTextField;