From 00f361455678f77584ab5f9315ef53fc1ffb5be5 Mon Sep 17 00:00:00 2001 From: nora-zajzon Date: Wed, 16 Oct 2024 11:39:12 -0700 Subject: [PATCH 1/3] Google Drive Validation --- client/src/components/data.js | 12 +++-- .../parts/form/ValidatedTextField.jsx | 47 +++++++++++-------- 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/client/src/components/data.js b/client/src/components/data.js index 6853ac113..368f2b4d5 100644 --- a/client/src/components/data.js +++ b/client/src/components/data.js @@ -39,29 +39,31 @@ export const simpleInputs = [ label: 'GitHub URL', name: 'githubUrl', type: 'text', - placeholder: 'htttps://github.com/', + placeholder: 'https://github.com/', disabled: false }, { label: 'Slack Channel Link', name: 'slackUrl', type: 'text', - placeholder: 'htttps://slack.com/', + placeholder: 'https://slack.com/', disabled: false }, { label: 'Google Drive URL', name: 'googleDriveUrl', type: 'text', - placeholder: 'htttps://drive.google.com/', + placeholder: 'https://drive.google.com/', disabled: false, - required: false + required: true, + pattern: /^https:\/\/drive\.google\.com\/.+$/, + errorMessage: 'Invalid Google Drive URL' }, { label: 'HFLA Website URL', name: 'hflaWebsiteUrl', type: 'text', - placeholder: 'htttps://hackforla.org/projects/', + placeholder: 'https://hackforla.org/projects/', disabled: false, required: false }, diff --git a/client/src/components/parts/form/ValidatedTextField.jsx b/client/src/components/parts/form/ValidatedTextField.jsx index 33f0e8d38..a8ac35499 100644 --- a/client/src/components/parts/form/ValidatedTextField.jsx +++ b/client/src/components/parts/form/ValidatedTextField.jsx @@ -24,27 +24,36 @@ function ValidatedTextField({ locationRadios, input, }) { - const inputObj = { - pattern: - input.name === 'location' - ? locationType === 'remote' - ? { - value: input.value, - message: input.errorMessage, - } - : { - value: input.addressValue, - message: input.addressError, - } - : { value: input.value, message: input.errorMessage }, - }; - if ('required' in input && input.required === false) { - // if required is set to false, don't add required attribute to object - } else { - inputObj.required = `${input.name} is required`; + + const validationRules = {}; + + // Validation rules for Google Drive URL + if (input.required) { + validationRules.required = `${input.label || input.name} is required` + } + if(input.name === 'googleDriveUrl'){ + validationRules.pattern = { + value: /^https:\/\/drive\.google\.com\/.+$/, + message: "Invalid Google Drive URL", // Pattern validation for Google Drive URL + }; + } + + if (input.name === 'location') { + if (locationType === 'remote') { + validationRules.pattern = { + value: input.value, + message: input.errorMessage || "Invalid remote location URL", + }; + } else { + validationRules.pattern = { + value: input.addressValue, + message: input.addressError || "Invalid physical address", + }; + } } + const registerObj = { - ...register(input.name, inputObj), + ...register(input.name, validationRules), } return ( From 6853a8205039d634d398070355a7a7934fff4cd1 Mon Sep 17 00:00:00 2001 From: nora-zajzon Date: Mon, 21 Oct 2024 19:48:54 -0700 Subject: [PATCH 2/3] testing push --- client/src/components/data.js | 1 + 1 file changed, 1 insertion(+) diff --git a/client/src/components/data.js b/client/src/components/data.js index 368f2b4d5..2ac9bcd8b 100644 --- a/client/src/components/data.js +++ b/client/src/components/data.js @@ -109,4 +109,5 @@ export const additionalInputsForEdit = [ // placeholder: 'Created Date', // disabled: true // } + //adding new line ] \ No newline at end of file From 5e7cc21cd3d53001f63d729bb56c376e2de4a779 Mon Sep 17 00:00:00 2001 From: nora-zajzon Date: Mon, 21 Oct 2024 19:53:07 -0700 Subject: [PATCH 3/3] undoing the test push --- client/src/components/data.js | 1 - 1 file changed, 1 deletion(-) diff --git a/client/src/components/data.js b/client/src/components/data.js index 2ac9bcd8b..368f2b4d5 100644 --- a/client/src/components/data.js +++ b/client/src/components/data.js @@ -109,5 +109,4 @@ export const additionalInputsForEdit = [ // placeholder: 'Created Date', // disabled: true // } - //adding new line ] \ No newline at end of file