From 884ae44fe1d3dbee2a2b942815611c1ea50e9927 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 27 Mar 2024 16:16:13 -0400 Subject: [PATCH 1/4] [new_profile] fix site not selecting automatically when 'Recruit another candidate' button is clicked --- modules/new_profile/jsx/NewProfileIndex.js | 273 +++++++++++---------- 1 file changed, 141 insertions(+), 132 deletions(-) mode change 100644 => 100755 modules/new_profile/jsx/NewProfileIndex.js diff --git a/modules/new_profile/jsx/NewProfileIndex.js b/modules/new_profile/jsx/NewProfileIndex.js old mode 100644 new mode 100755 index cdcdfe58e67..936dd5cfdcc --- a/modules/new_profile/jsx/NewProfileIndex.js +++ b/modules/new_profile/jsx/NewProfileIndex.js @@ -1,15 +1,15 @@ import Loader from 'Loader'; import swal from 'sweetalert2'; -import {createRoot} from 'react-dom/client'; +import { createRoot } from 'react-dom/client'; import React from 'react'; import PropTypes from 'prop-types'; import { - SelectElement, - DateElement, - TextboxElement, - FormElement, - ButtonElement, - FieldsetElement, + SelectElement, + DateElement, + TextboxElement, + FormElement, + ButtonElement, + FieldsetElement, } from 'jsx/Form'; /** @@ -44,7 +44,7 @@ class NewProfileIndex extends React.Component { */ componentDidMount() { this.fetchData() - .then(() => this.setState({isLoaded: true})); + .then(() => this.setState({ isLoaded: true })); } /** @@ -54,11 +54,11 @@ class NewProfileIndex extends React.Component { */ fetchData() { return fetch(this.props.dataURL, - {credentials: 'same-origin'}) + { credentials: 'same-origin' }) .then((resp) => resp.json()) - .then((data) => this.setState({configData: data.fieldOptions})) + .then((data) => this.setState({ configData: data.fieldOptions })) .catch((error) => { - this.setState({error: true}); + this.setState({ error: true }); }); } /** @@ -74,7 +74,7 @@ class NewProfileIndex extends React.Component { if (formData.dobDate !== formData.dobDateConfirm) { swal.fire('Error!', 'Date of Birth fields must match', 'error'); } else if (this.state.configData['edc'] === 'true' && - (formData.edcDate !== formData.edcDateConfirm) + (formData.edcDate !== formData.edcDateConfirm) ) { swal.fire('Error!', 'EDC fields must match', 'error'); } else { @@ -116,7 +116,7 @@ class NewProfileIndex extends React.Component { } // disable button to prevent form resubmission. - this.setState({submitDisabled: true}); + this.setState({ submitDisabled: true }); fetch(this.props.submitURL, { method: 'POST', @@ -124,63 +124,72 @@ class NewProfileIndex extends React.Component { credentials: 'same-origin', body: JSON.stringify(candidateObject), }) - .then((resp) => { - if (resp.ok && resp.status === 201) { - resp.json().then((data) => { - swal.fire({ - type: 'success', - title: 'New Candidate Created', - html: 'DCCID: ' + data.CandID + ' ' - + 'PSCID: ' + data.PSCID + ' ', - confirmButtonText: 'Access Profile', - // Repurpose "cancel" as "recruit another candidate". - // Use the same colour for both buttons, since one - // isn't more "right" than the other. - showCancelButton: true, - cancelButtonColor: '#3085d6', - cancelButtonText: 'Recruit another candidate', - }).then((result) => { - if (result.value === true) { - window.location.href = '/' + data.CandID; - } else { - this.setState({ - formData: {}, - submitDisabled: false, + .then((resp) => { + if (resp.ok && resp.status === 201) { + resp.json().then((data) => { + swal.fire({ + type: 'success', + title: 'New Candidate Created', + html: 'DCCID: ' + data.CandID + ' ' + + 'PSCID: ' + data.PSCID + ' ', + confirmButtonText: 'Access Profile', + // Repurpose "cancel" as "recruit another candidate". + // Use the same colour for both buttons, since one + // isn't more "right" than the other. + showCancelButton: true, + cancelButtonColor: '#3085d6', + cancelButtonText: 'Recruit another candidate', + }).then((result) => { + if (result.value === true) { + window.location.href = '/' + data.CandID; + } else { + this.setState({ + formData: { + edcDate: null, + edcDateConfirm: null, + pscid: null, + site: this.state.formData.site, + dobDate: null, + dobDateConfirm: null, + sex: null, + project: null, + }, + submitDisabled: false, + }); + } + }); + }) + .catch((error) => { + swal.fire({ + type: 'error', + title: 'Error!', + text: error, }); - } + console.error(error); + }); + } else { + resp.json().then((message) => { + // enable button for form resubmission. + this.setState({ submitDisabled: false }); + swal.fire('Error!', message.error, 'error'); + }).catch((error) => { + swal.fire({ + type: 'error', + title: 'Error!', + text: error, + }); + console.error(error); }); - } ) - .catch((error) => { - swal.fire({ - type: 'error', - title: 'Error!', - text: error, - }); - console.error(error); - }); - } else { - resp.json().then((message) => { - // enable button for form resubmission. - this.setState({submitDisabled: false}); - swal.fire('Error!', message.error, 'error'); - }).catch((error) => { - swal.fire({ - type: 'error', - title: 'Error!', - text: error, - }); - console.error(error); + } + }) + .catch((error) => { + swal.fire({ + type: 'error', + title: 'Error!', + text: error, }); - } - }) - .catch((error) => { - swal.fire({ - type: 'error', - title: 'Error!', - text: error, + console.error(error); }); - console.error(error); - }); } /** @@ -193,7 +202,7 @@ class NewProfileIndex extends React.Component { let formData = Object.assign({}, this.state.formData); formData[formElement] = value; - this.setState({formData: formData}); + this.setState({ formData: formData }); } /** @@ -209,7 +218,7 @@ class NewProfileIndex extends React.Component { // Waiting for async data to load if (!this.state.isLoaded) { - return ; + return ; } let edc = null; let pscid = null; @@ -228,97 +237,97 @@ class NewProfileIndex extends React.Component { edc =
; } if (this.state.configData['pscidSet'] === 'true') { pscid = ; } if (this.state.configData.site && this.state.configData.site.length !== 0) { site = ; } const profile = ( {edc} {site} {pscid} @@ -340,9 +349,9 @@ window.addEventListener('load', () => { document.getElementById('lorisworkspace') ).render( ); }); From ea63389a341a2cac8093a54022bf83591e6108d9 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 27 Mar 2024 16:19:25 -0400 Subject: [PATCH 2/4] format --- modules/new_profile/jsx/NewProfileIndex.js | 282 ++++++++++----------- 1 file changed, 141 insertions(+), 141 deletions(-) diff --git a/modules/new_profile/jsx/NewProfileIndex.js b/modules/new_profile/jsx/NewProfileIndex.js index 936dd5cfdcc..2b9bdf8aa63 100755 --- a/modules/new_profile/jsx/NewProfileIndex.js +++ b/modules/new_profile/jsx/NewProfileIndex.js @@ -1,15 +1,15 @@ import Loader from 'Loader'; import swal from 'sweetalert2'; -import { createRoot } from 'react-dom/client'; +import {createRoot} from 'react-dom/client'; import React from 'react'; import PropTypes from 'prop-types'; import { - SelectElement, - DateElement, - TextboxElement, - FormElement, - ButtonElement, - FieldsetElement, + SelectElement, + DateElement, + TextboxElement, + FormElement, + ButtonElement, + FieldsetElement, } from 'jsx/Form'; /** @@ -44,7 +44,7 @@ class NewProfileIndex extends React.Component { */ componentDidMount() { this.fetchData() - .then(() => this.setState({ isLoaded: true })); + .then(() => this.setState({isLoaded: true})); } /** @@ -54,11 +54,11 @@ class NewProfileIndex extends React.Component { */ fetchData() { return fetch(this.props.dataURL, - { credentials: 'same-origin' }) + {credentials: 'same-origin'}) .then((resp) => resp.json()) - .then((data) => this.setState({ configData: data.fieldOptions })) + .then((data) => this.setState({configData: data.fieldOptions})) .catch((error) => { - this.setState({ error: true }); + this.setState({error: true}); }); } /** @@ -74,7 +74,7 @@ class NewProfileIndex extends React.Component { if (formData.dobDate !== formData.dobDateConfirm) { swal.fire('Error!', 'Date of Birth fields must match', 'error'); } else if (this.state.configData['edc'] === 'true' && - (formData.edcDate !== formData.edcDateConfirm) + (formData.edcDate !== formData.edcDateConfirm) ) { swal.fire('Error!', 'EDC fields must match', 'error'); } else { @@ -116,7 +116,7 @@ class NewProfileIndex extends React.Component { } // disable button to prevent form resubmission. - this.setState({ submitDisabled: true }); + this.setState({submitDisabled: true}); fetch(this.props.submitURL, { method: 'POST', @@ -124,72 +124,72 @@ class NewProfileIndex extends React.Component { credentials: 'same-origin', body: JSON.stringify(candidateObject), }) - .then((resp) => { - if (resp.ok && resp.status === 201) { - resp.json().then((data) => { - swal.fire({ - type: 'success', - title: 'New Candidate Created', - html: 'DCCID: ' + data.CandID + ' ' - + 'PSCID: ' + data.PSCID + ' ', - confirmButtonText: 'Access Profile', - // Repurpose "cancel" as "recruit another candidate". - // Use the same colour for both buttons, since one - // isn't more "right" than the other. - showCancelButton: true, - cancelButtonColor: '#3085d6', - cancelButtonText: 'Recruit another candidate', - }).then((result) => { - if (result.value === true) { - window.location.href = '/' + data.CandID; - } else { - this.setState({ - formData: { - edcDate: null, - edcDateConfirm: null, - pscid: null, - site: this.state.formData.site, - dobDate: null, - dobDateConfirm: null, - sex: null, - project: null, - }, - submitDisabled: false, - }); - } - }); - }) - .catch((error) => { - swal.fire({ - type: 'error', - title: 'Error!', - text: error, + .then((resp) => { + if (resp.ok && resp.status === 201) { + resp.json().then((data) => { + swal.fire({ + type: 'success', + title: 'New Candidate Created', + html: 'DCCID: ' + data.CandID + ' ' + + 'PSCID: ' + data.PSCID + ' ', + confirmButtonText: 'Access Profile', + // Repurpose "cancel" as "recruit another candidate". + // Use the same colour for both buttons, since one + // isn't more "right" than the other. + showCancelButton: true, + cancelButtonColor: '#3085d6', + cancelButtonText: 'Recruit another candidate', + }).then((result) => { + if (result.value === true) { + window.location.href = '/' + data.CandID; + } else { + this.setState({ + formData: { + edcDate: null, + edcDateConfirm: null, + pscid: null, + site: this.state.formData.site, + dobDate: null, + dobDateConfirm: null, + sex: null, + project: null, + }, + submitDisabled: false, }); - console.error(error); - }); - } else { - resp.json().then((message) => { - // enable button for form resubmission. - this.setState({ submitDisabled: false }); - swal.fire('Error!', message.error, 'error'); - }).catch((error) => { - swal.fire({ - type: 'error', - title: 'Error!', - text: error, - }); - console.error(error); + } }); - } - }) - .catch((error) => { - swal.fire({ - type: 'error', - title: 'Error!', - text: error, + } ) + .catch((error) => { + swal.fire({ + type: 'error', + title: 'Error!', + text: error, + }); + console.error(error); }); - console.error(error); + } else { + resp.json().then((message) => { + // enable button for form resubmission. + this.setState({submitDisabled: false}); + swal.fire('Error!', message.error, 'error'); + }).catch((error) => { + swal.fire({ + type: 'error', + title: 'Error!', + text: error, + }); + console.error(error); + }); + } + }) + .catch((error) => { + swal.fire({ + type: 'error', + title: 'Error!', + text: error, }); + console.error(error); + }); } /** @@ -202,7 +202,7 @@ class NewProfileIndex extends React.Component { let formData = Object.assign({}, this.state.formData); formData[formElement] = value; - this.setState({ formData: formData }); + this.setState({formData: formData}); } /** @@ -218,7 +218,7 @@ class NewProfileIndex extends React.Component { // Waiting for async data to load if (!this.state.isLoaded) { - return ; + return ; } let edc = null; let pscid = null; @@ -237,97 +237,97 @@ class NewProfileIndex extends React.Component { edc =
; } if (this.state.configData['pscidSet'] === 'true') { pscid = ; } if (this.state.configData.site && this.state.configData.site.length !== 0) { site = ; } const profile = ( {edc} {site} {pscid} @@ -349,9 +349,9 @@ window.addEventListener('load', () => { document.getElementById('lorisworkspace') ).render( ); }); From 41b929fae0c311c3430b0c5ae2e8a9255863658e Mon Sep 17 00:00:00 2001 From: root Date: Wed, 27 Mar 2024 16:34:35 -0400 Subject: [PATCH 3/4] updates --- modules/new_profile/jsx/NewProfileIndex.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/new_profile/jsx/NewProfileIndex.js b/modules/new_profile/jsx/NewProfileIndex.js index 2b9bdf8aa63..96eb1fa2b3f 100755 --- a/modules/new_profile/jsx/NewProfileIndex.js +++ b/modules/new_profile/jsx/NewProfileIndex.js @@ -148,7 +148,7 @@ class NewProfileIndex extends React.Component { edcDate: null, edcDateConfirm: null, pscid: null, - site: this.state.formData.site, + site: this.state.formData.site, dobDate: null, dobDateConfirm: null, sex: null, From 092907039007e2c7e33c9bc719c163a1c38d4d64 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 27 Mar 2024 20:17:06 -0400 Subject: [PATCH 4/4] fix changes --- modules/new_profile/jsx/NewProfileIndex.js | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/modules/new_profile/jsx/NewProfileIndex.js b/modules/new_profile/jsx/NewProfileIndex.js index 96eb1fa2b3f..4353fda6e43 100755 --- a/modules/new_profile/jsx/NewProfileIndex.js +++ b/modules/new_profile/jsx/NewProfileIndex.js @@ -143,19 +143,7 @@ class NewProfileIndex extends React.Component { if (result.value === true) { window.location.href = '/' + data.CandID; } else { - this.setState({ - formData: { - edcDate: null, - edcDateConfirm: null, - pscid: null, - site: this.state.formData.site, - dobDate: null, - dobDateConfirm: null, - sex: null, - project: null, - }, - submitDisabled: false, - }); + window.location.href = '/new_profile/'; } }); } )