From 2fe6e3ebb8176ac3ac0c3e03d7c59f269f34c837 Mon Sep 17 00:00:00 2001 From: Ndibe Raymond Olisaemeka Date: Fri, 22 Jan 2021 20:26:54 +0100 Subject: [PATCH] Revert "Added more actions to profile dropdown (#84)" (#85) This reverts commit 271408a0cf132863759bfd8a2d510b07c0106832. --- .../zubhub/docker-compose.prod.yml | 6 - zubhub_frontend/zubhub/docker-compose.yml | 4 - zubhub_frontend/zubhub/package-lock.json | 27 ---- zubhub_frontend/zubhub/package.json | 4 +- .../zubhub/src/assets/js/Compress.js | 39 ----- .../src/assets/js/removeMetaDataWorker.js | 62 -------- .../js/styles/views/signup/signupStyles.js | 5 - .../zubhub/src/store/actions/authActions.js | 91 ++++++++--- .../src/store/actions/projectActions.js | 30 +++- .../zubhub/src/views/PageWrapper.jsx | 42 ----- .../views/create_project/CreateProject.jsx | 146 +++++------------- .../src/views/email_confirm/EmailConfirm.jsx | 11 +- .../zubhub/src/views/login/Login.jsx | 21 +-- .../views/password_reset/PasswordReset.jsx | 21 +-- .../PasswordResetConfirm.jsx | 23 +-- .../zubhub/src/views/profile/Profile.jsx | 28 +--- .../views/project_details/ProjectDetails.jsx | 1 + .../zubhub/src/views/signup/Signup.jsx | 31 +--- 18 files changed, 140 insertions(+), 452 deletions(-) delete mode 100644 zubhub_frontend/zubhub/src/assets/js/Compress.js delete mode 100644 zubhub_frontend/zubhub/src/assets/js/removeMetaDataWorker.js diff --git a/zubhub_frontend/zubhub/docker-compose.prod.yml b/zubhub_frontend/zubhub/docker-compose.prod.yml index 16bc8b02a..e0c527af6 100644 --- a/zubhub_frontend/zubhub/docker-compose.prod.yml +++ b/zubhub_frontend/zubhub/docker-compose.prod.yml @@ -5,15 +5,9 @@ services: container_name: zubhub_frontend build: context: . -<<<<<<< HEAD - dockerfile: Dockerfile - volumes: - - ./nginx/default.conf:/etc/nginx/conf.d/default.conf -======= dockerfile: Dockerfile.prod volumes: - ./nginx/prod/default.conf:/etc/nginx/conf.d/default.conf ->>>>>>> e27329f26fe2cff77464c3965a2859d1d6c0b01f restart: on-failure ports: - "80" diff --git a/zubhub_frontend/zubhub/docker-compose.yml b/zubhub_frontend/zubhub/docker-compose.yml index a2dcab6a4..7db4ee546 100644 --- a/zubhub_frontend/zubhub/docker-compose.yml +++ b/zubhub_frontend/zubhub/docker-compose.yml @@ -10,8 +10,4 @@ services: - ./nginx/dev/default.conf:/etc/nginx/conf.d/default.conf restart: on-failure ports: -<<<<<<< HEAD - - "80:80" -======= - "3000:3000" ->>>>>>> e27329f26fe2cff77464c3965a2859d1d6c0b01f diff --git a/zubhub_frontend/zubhub/package-lock.json b/zubhub_frontend/zubhub/package-lock.json index 20d60cf5d..b1c50af10 100644 --- a/zubhub_frontend/zubhub/package-lock.json +++ b/zubhub_frontend/zubhub/package-lock.json @@ -3424,11 +3424,6 @@ "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==" }, - "blueimp-canvas-to-blob": { - "version": "3.28.0", - "resolved": "https://registry.npmjs.org/blueimp-canvas-to-blob/-/blueimp-canvas-to-blob-3.28.0.tgz", - "integrity": "sha512-5q+YHzgGsuHQ01iouGgJaPJXod2AzTxJXmVv90PpGrRxU7G7IqgPqWXz+PBmt3520jKKi6irWbNV87DicEa7wg==" - }, "bn.js": { "version": "5.1.3", "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-5.1.3.tgz", @@ -4180,15 +4175,6 @@ } } }, - "compressorjs": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/compressorjs/-/compressorjs-1.0.7.tgz", - "integrity": "sha512-ca+H8CGrn0LG103//VQmXBbNdvzvHiW26LGdWncp4RmLNbNQjaaFWIUxMN9++hbhGobLtofkHoxzzXGisNyD3w==", - "requires": { - "blueimp-canvas-to-blob": "^3.28.0", - "is-blob": "^2.1.0" - } - }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -7723,11 +7709,6 @@ "binary-extensions": "^2.0.0" } }, - "is-blob": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/is-blob/-/is-blob-2.1.0.tgz", - "integrity": "sha512-SZ/fTft5eUhQM6oF/ZaASFDEdbFVe89Imltn9uZr03wdKMcWNVYSMjQPFtg05QuNkt5l5c135ElvXEQG0rk4tw==" - }, "is-buffer": { "version": "1.1.6", "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz", @@ -16447,14 +16428,6 @@ "microevent.ts": "~0.1.1" } }, - "workerize-loader": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/workerize-loader/-/workerize-loader-1.3.0.tgz", - "integrity": "sha512-utWDc8K6embcICmRBUUkzanPgKBb8yM1OHfh6siZfiMsswE8wLCa9CWS+L7AARz0+Th4KH4ZySrqer/OJ9WuWw==", - "requires": { - "loader-utils": "^2.0.0" - } - }, "wrap-ansi": { "version": "6.2.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz", diff --git a/zubhub_frontend/zubhub/package.json b/zubhub_frontend/zubhub/package.json index 472e0d408..c24a548ff 100644 --- a/zubhub_frontend/zubhub/package.json +++ b/zubhub_frontend/zubhub/package.json @@ -12,7 +12,6 @@ "@testing-library/user-event": "^12.2.2", "aws-sdk": "^2.813.0", "classnames": "^2.2.6", - "compressorjs": "^1.0.7", "date-fns": "^2.16.1", "formik": "^2.2.5", "nanoid": "^3.1.20", @@ -28,7 +27,6 @@ "redux-thunk": "^2.3.0", "slick-carousel": "^1.8.1", "web-vitals": "^0.2.4", - "workerize-loader": "^1.3.0", "yup": "^0.29.3" }, "scripts": { @@ -57,6 +55,6 @@ ] }, "devDependencies": { - "prettier": "^2.2.1" + "prettier": "2.2.1" } } diff --git a/zubhub_frontend/zubhub/src/assets/js/Compress.js b/zubhub_frontend/zubhub/src/assets/js/Compress.js deleted file mode 100644 index f4aec897c..000000000 --- a/zubhub_frontend/zubhub/src/assets/js/Compress.js +++ /dev/null @@ -1,39 +0,0 @@ -import Compressor from 'compressorjs'; - -const Compress = (images, state, handleSetState) => { - let compressed = []; - - for (let index = 0; index < images.length; index += 1) { - let image = images[index]; - - if (image && image.type.split('/')[1] !== 'gif') { - new Compressor(image, { - quality: 0.6, - convertSize: 100000, - success: result => { - compressed.push(result); - shouldSetImages(compressed, images, state, handleSetState); - }, - error: error => { - console.warn(error.message); - compressed.push(image); - shouldSetImages(compressed, images, state, handleSetState); - }, - }); - } else { - compressed.push(image); - shouldSetImages(compressed, images, state, handleSetState); - } - } -}; - -const shouldSetImages = (compressed, images, state, handleSetState) => { - if (compressed.length === images.length) { - const { image_upload } = state; - image_upload.images_to_upload = compressed; - - handleSetState(image_upload); - } -}; - -export default Compress; diff --git a/zubhub_frontend/zubhub/src/assets/js/removeMetaDataWorker.js b/zubhub_frontend/zubhub/src/assets/js/removeMetaDataWorker.js deleted file mode 100644 index 166abf3f2..000000000 --- a/zubhub_frontend/zubhub/src/assets/js/removeMetaDataWorker.js +++ /dev/null @@ -1,62 +0,0 @@ -export const removeMetaData = imageArr => { - let newImageArr = []; - - for (let index = 0; index < imageArr.length; index++) { - let fr = new FileReader(); - fr.onload = process; - fr.mainFile = imageArr[index]; - fr.readAsArrayBuffer(imageArr[index]); - } - - function process() { - let dv = new DataView(this.result); - let offset = 0, - recess = 0; - let pieces = []; - let i = 0; - if (dv.getUint16(offset) === 0xffd8) { - offset += 2; - let app1 = dv.getUint16(offset); - offset += 2; - while (offset < dv.byteLength) { - if (app1 === 0xffe1) { - pieces[i] = { recess: recess, offset: offset - 2 }; - recess = offset + dv.getUint16(offset); - i++; - } else if (app1 === 0xffda) { - break; - } - offset += dv.getUint16(offset); - app1 = dv.getUint16(offset); - offset += 2; - } - - if (pieces.length > 0) { - let newPieces = []; - pieces.forEach(function (v) { - newPieces.push(this.result.slice(v.recess, v.offset)); - }, this); - newPieces.push(this.result.slice(recess)); - newImageArr.push( - new Blob(newPieces, { type: imageArr[newImageArr.length].type }), - ); - - if (newImageArr.length === imageArr.length) { - postMessage(newImageArr); - } - } else { - newImageArr.push(this.mainFile); - - if (newImageArr.length === imageArr.length) { - postMessage(newImageArr); - } - } - } else { - newImageArr.push(this.mainFile); - - if (newImageArr.length === imageArr.length) { - postMessage(newImageArr); - } - } - } -}; diff --git a/zubhub_frontend/zubhub/src/assets/js/styles/views/signup/signupStyles.js b/zubhub_frontend/zubhub/src/assets/js/styles/views/signup/signupStyles.js index 6b0e75171..751895f43 100644 --- a/zubhub_frontend/zubhub/src/assets/js/styles/views/signup/signupStyles.js +++ b/zubhub_frontend/zubhub/src/assets/js/styles/views/signup/signupStyles.js @@ -42,11 +42,6 @@ const styles = theme => ({ }, }, }, - DOBInputStyle: { - '&.MuiOutlinedInput-root fieldset legend': { - width: '75.5px !important', - }, - }, secondaryLink: { color: '#00B8C4', '&:hover': { diff --git a/zubhub_frontend/zubhub/src/store/actions/authActions.js b/zubhub_frontend/zubhub/src/store/actions/authActions.js index e391e3c76..877810508 100644 --- a/zubhub_frontend/zubhub/src/store/actions/authActions.js +++ b/zubhub_frontend/zubhub/src/store/actions/authActions.js @@ -17,14 +17,27 @@ export const login = props => { return API.login(props.values) .then(res => { if (!res.key) { - throw new Error(JSON.stringify(res)); + res = Object.keys(res) + .map(key => res[key]) + .join('\n'); + throw new Error(res); } dispatch({ type: 'SET_AUTH_USER', payload: { token: res.key }, }); }) - .then(() => props.history.push('/profile')); + .then(() => props.history.push('/profile')) + .catch(error => { + if (error.message.startsWith('Unexpected')) { + return { + error: + 'An error occured while performing this action. Please try again later', + }; + } else { + return { error: error.message }; + } + }); }; }; @@ -72,61 +85,95 @@ export const signup = props => { return API.signup(props.values) .then(res => { if (!res.key) { - throw new Error(JSON.stringify(res)); + res = Object.keys(res) + .map(key => res[key]) + .join('\n'); + throw new Error(res); } dispatch({ type: 'SET_AUTH_USER', payload: { token: res.key }, }); }) - .then(() => props.history.push('/profile')); + .then(() => props.history.push('/profile')) + .catch(error => { + if (error.message.startsWith('Unexpected')) { + return { + error: + 'An error occured while performing this action. Please try again later', + }; + } else { + return { error: error.message }; + } + }); }; }; export const send_email_confirmation = (props, key) => { return () => { - return API.send_email_confirmation(key).then(res => { - if (res.detail !== 'ok') { - throw new Error(res.detail); - } else { + return API.send_email_confirmation(key) + .then(res => { toast.success('Congratulations!, your email has been confirmed!'); setTimeout(() => { props.history.push('/'); }, 4000); - } - }); + }) + .catch(error => { + if (error.message.startsWith('Unexpected')) { + return { + error: + 'An error occured while performing this action. Please try again later', + }; + } else { + return { error: error.message }; + } + }); }; }; export const send_password_reset_link = props => { return () => { - return API.send_password_reset_link(props.values.email).then(res => { - if (res.detail !== 'Password reset e-mail has been sent.') { - throw new Error(JSON.stringify(res)); - } else { + return API.send_password_reset_link(props.values.email) + .then(res => { toast.success('We just sent a password reset link to your email!'); setTimeout(() => { props.history.push('/'); }, 4000); - } - }); + }) + .catch(error => { + if (error.message.startsWith('Unexpected')) { + return { + error: + 'An error occured while performing this action. Please try again later', + }; + } else { + return { error: error.message }; + } + }); }; }; export const password_reset_confirm = props => { return () => { - return API.password_reset_confirm(props).then(res => { - if (res.detail !== 'Password has been reset with the new password.') { - throw new Error(JSON.stringify(res)); - } else { + return API.password_reset_confirm(props) + .then(res => { toast.success( 'Congratulations! your password reset was successful! you will now be redirected to login', ); setTimeout(() => { props.history.push('/login'); }, 4000); - } - }); + }) + .catch(error => { + if (error.message.startsWith('Unexpected')) { + return { + error: + 'An error occured while performing this action. Please try again later', + }; + } else { + return { error: error.message }; + } + }); }; }; diff --git a/zubhub_frontend/zubhub/src/store/actions/projectActions.js b/zubhub_frontend/zubhub/src/store/actions/projectActions.js index e7d3176f4..2254c7a7b 100644 --- a/zubhub_frontend/zubhub/src/store/actions/projectActions.js +++ b/zubhub_frontend/zubhub/src/store/actions/projectActions.js @@ -13,14 +13,28 @@ export const set_projects = projects => { export const create_project = props => { return dispatch => { - return API.create_project(props).then(res => { - if (!res.id) { - throw new Error(JSON.stringify(res)); - } else { - toast.success('Your project was created successfully!!'); - return props.history.push('/profile'); - } - }); + return API.create_project(props) + .then(res => { + if (!res.comments) { + res = Object.keys(res) + .map(key => res[key]) + .join('\n'); + throw new Error(res); + } else { + toast.success('Your project was created successfully!!'); + return props.history.push('/profile'); + } + }) + .catch(error => { + if (error.message.startsWith('Unexpected')) { + return { + error: + 'An error occured while performing this action. Please try again later', + }; + } else { + return { error: error.message }; + } + }); }; }; diff --git a/zubhub_frontend/zubhub/src/views/PageWrapper.jsx b/zubhub_frontend/zubhub/src/views/PageWrapper.jsx index 75cbe3c5e..d090c93c9 100644 --- a/zubhub_frontend/zubhub/src/views/PageWrapper.jsx +++ b/zubhub_frontend/zubhub/src/views/PageWrapper.jsx @@ -170,48 +170,6 @@ function PageWrapper(props) { - - - - Projects - - - - - - - Followers - - - - - - - Following - - - { +const handleImageFieldChange = (e, refs, props) => { + props.setFieldValue(e.currentTarget.name, refs.imageEl.current); refs.imageCountEl.current.innerText = refs.imageEl.current.files.length; refs.imageCountEl.current.style.fontSize = '0.8rem'; - - props.setFieldValue('project_images', refs.imageEl.current).then(errors => { - if (!errors['project_images']) { - removeMetaData(refs.imageEl.current.files, state, handleSetState); - } - }); -}; - -const removeMetaData = (images, state, handleSetState) => { - const newWorker = worker(); - newWorker.removeMetaData(images); - newWorker.addEventListener('message', e => { - Compress(e.data, state, handleSetState); - }); }; const handleImageButtonClick = (e, props, refs) => { @@ -132,7 +117,7 @@ function CreateProject(props) { useStateUpdateCallback(() => { if ( - state.image_upload.images_to_upload.length === + state.image_upload.images_to_upload === state.image_upload.successful_uploads ) { handleSetState(upload_project()); @@ -228,33 +213,12 @@ function CreateProject(props) { const { image_upload } = state; image_upload.upload_dialog = false; handleSetState({ image_upload }); - return props - .create_project({ - ...props.values, - token: props.auth.token, - images: state.image_upload.uploaded_images_url, - video: props.values.video ? props.values.video : '', - }) - .catch(error => { - const messages = JSON.parse(error.message); - if (typeof messages === 'object') { - let non_field_errors; - Object.keys(messages).forEach(key => { - if (key === 'non_field_errors') { - non_field_errors = { error: messages[key][0] }; - } else { - props.setFieldTouched(key, true, false); - props.setFieldError(key, messages[key][0]); - } - }); - if (non_field_errors) return non_field_errors; - } else { - return { - error: - 'An error occured while performing this action. Please try again later', - }; - } - }); + return props.create_project({ + ...props.values, + token: props.auth.token, + images: state.image_upload.uploaded_images_url, + video: props.values.video ? props.values.video : '', + }); }; const init_project = e => { @@ -267,30 +231,35 @@ function CreateProject(props) { props.setFieldTouched('project_images'); props.setFieldTouched('video'); props.setFieldTouched('materials_used'); + props.validateField('title'); + props.validateField('description'); + props.validateField('project_images'); + props.validateField('video'); + props.validateField('materials_used'); + + if ( + props.errors['title'] || + props.errors['description'] || + props.errors['project_images'] || + props.errors['video'] || + props.errors['materials_used'] + ) { + return; + } else if (refs.imageEl.current.files.length === 0) { + handleSetState(upload_project()); + } else { + const project_images = refs.imageEl.current.files; - image_field_touched = true; - video_field_touched = true; - - props.validateForm().then(errors => { - if (Object.keys(errors).length > 0) { - return; - } else if (refs.imageEl.current.files.length === 0) { - handleSetState(upload_project()); - } else { - const { image_upload } = state; - image_upload.upload_dialog = true; - image_upload.upload_percent = 0; - handleSetState({ image_upload }); + const { image_upload } = state; + image_upload.images_to_upload = project_images.length; + image_upload.upload_dialog = true; + image_upload.upload_percent = 0; + handleSetState({ image_upload }); - for ( - let index = 0; - index < image_upload.images_to_upload.length; - index++ - ) { - upload(image_upload.images_to_upload[index]); - } + for (let index = 0; index < project_images.length; index++) { + upload(project_images[index]); } - }); + } } }; @@ -409,17 +378,6 @@ function CreateProject(props) { labelWidth={90} /> - - Tell us something interesting about the project! You - can share what it is about, what inspired you to - make it, your making process, fun and challenging - moments you experienced, etc. - -
{props.touched['description'] && props.errors['description']}
@@ -467,14 +425,7 @@ function CreateProject(props) { id="project_images" name="project_images" multiple - onChange={e => - handleImageFieldChange( - refs, - props, - state, - handleSetState, - ) - } + onChange={e => handleImageFieldChange(e, refs, props)} onBlur={props.handleBlur} /> @@ -509,14 +460,6 @@ function CreateProject(props) { labelWidth={90} /> - - YouTube, Vimeo, Google Drive links are supported - -
{props.touched['video'] && props.errors['video']}
@@ -725,19 +668,6 @@ export default connect( : true; }, ) - .test('not_an_image', 'only images are allowed', value => { - if (value) { - let not_an_image = false; - for (let index = 0; index < value.files.length; index++) { - if (value.files[index].type.split('/')[0] !== 'image') { - not_an_image = true; - } - } - return not_an_image ? false : true; - } else { - return true; - } - }) .test('too_many_images', 'too many images uploaded', value => { if (value) { return value.files.length > 10 ? false : true; @@ -747,12 +677,12 @@ export default connect( }) .test( 'image_size_too_large', - 'one or more of your image is greater than 10mb', + 'one or more of your image is greater than 3mb', value => { if (value) { let image_size_too_large = false; for (let index = 0; index < value.files.length; index++) { - if (value.files[index].size / 1000 > 10240) { + if (value.files[index].size / 1000 > 3072) { image_size_too_large = true; } } diff --git a/zubhub_frontend/zubhub/src/views/email_confirm/EmailConfirm.jsx b/zubhub_frontend/zubhub/src/views/email_confirm/EmailConfirm.jsx index c67fd2e06..f5d22e46b 100644 --- a/zubhub_frontend/zubhub/src/views/email_confirm/EmailConfirm.jsx +++ b/zubhub_frontend/zubhub/src/views/email_confirm/EmailConfirm.jsx @@ -31,16 +31,7 @@ const getUsernameAndKey = queryString => { const confirmEmail = (e, props, state) => { e.preventDefault(); - return props.send_email_confirmation(props, state.key).catch(error => { - if (error.message.startsWith('Unexpected')) { - return { - error: - 'An error occured while performing this action. Please try again later', - }; - } else { - return { error: error.message }; - } - }); + return props.send_email_confirmation(props, state.key); }; function EmailConfirm(props) { diff --git a/zubhub_frontend/zubhub/src/views/login/Login.jsx b/zubhub_frontend/zubhub/src/views/login/Login.jsx index 5bb75a3ca..9cc98a2de 100644 --- a/zubhub_frontend/zubhub/src/views/login/Login.jsx +++ b/zubhub_frontend/zubhub/src/views/login/Login.jsx @@ -45,26 +45,7 @@ const handleMouseDownPassword = e => { const login = (e, props) => { e.preventDefault(); - return props.login(props).catch(error => { - const messages = JSON.parse(error.message); - if (typeof messages === 'object') { - let non_field_errors; - Object.keys(messages).forEach(key => { - if (key === 'non_field_errors') { - non_field_errors = { error: messages[key][0] }; - } else { - props.setFieldTouched(key, true, false); - props.setFieldError(key, messages[key][0]); - } - }); - return non_field_errors; - } else { - return { - error: - 'An error occured while performing this action. Please try again later', - }; - } - }); + return props.login(props); }; function Login(props) { diff --git a/zubhub_frontend/zubhub/src/views/password_reset/PasswordReset.jsx b/zubhub_frontend/zubhub/src/views/password_reset/PasswordReset.jsx index cf1ff7ba3..5156b237f 100644 --- a/zubhub_frontend/zubhub/src/views/password_reset/PasswordReset.jsx +++ b/zubhub_frontend/zubhub/src/views/password_reset/PasswordReset.jsx @@ -30,26 +30,7 @@ const useStyles = makeStyles(styles); const sendPasswordResetLink = (e, props) => { e.preventDefault(); - return props.send_password_reset_link(props).catch(error => { - const messages = JSON.parse(error.message); - let non_field_errors; - if (typeof messages === 'object') { - Object.keys(messages).forEach(key => { - if (key !== 'email') { - non_field_errors = { error: messages[key][0] }; - } else { - props.setFieldTouched(key, true, false); - props.setFieldError(key, messages[key][0]); - } - }); - return non_field_errors; - } else { - return { - error: - 'An error occured while performing this action. Please try again later', - }; - } - }); + return props.send_password_reset_link(props); }; function PasswordReset(props) { diff --git a/zubhub_frontend/zubhub/src/views/password_reset_confirm/PasswordResetConfirm.jsx b/zubhub_frontend/zubhub/src/views/password_reset_confirm/PasswordResetConfirm.jsx index b87775979..1f510d032 100644 --- a/zubhub_frontend/zubhub/src/views/password_reset_confirm/PasswordResetConfirm.jsx +++ b/zubhub_frontend/zubhub/src/views/password_reset_confirm/PasswordResetConfirm.jsx @@ -44,28 +44,7 @@ const getUidAndToken = queryString => { const resetPassword = (e, props) => { e.preventDefault(); const { uid, token } = getUidAndToken(props.location.search); - return props - .password_reset_confirm({ ...props.values, uid, token }) - .catch(error => { - const messages = JSON.parse(error.message); - if (typeof messages === 'object') { - let non_field_errors; - Object.keys(messages).forEach(key => { - if (key !== 'new_password1' && key !== 'new_password2') { - non_field_errors = { error: messages[key][0] }; - } else { - props.setFieldTouched(key, true, false); - props.setFieldError(key, messages[key][0]); - } - }); - return non_field_errors; - } else { - return { - error: - 'An error occured while performing this action. Please try again later', - }; - } - }); + return props.password_reset_confirm({ ...props.values, uid, token }); }; const handleClickShowPassword = (field, state) => { diff --git a/zubhub_frontend/zubhub/src/views/profile/Profile.jsx b/zubhub_frontend/zubhub/src/views/profile/Profile.jsx index 23feb32f4..bbfa64ad3 100644 --- a/zubhub_frontend/zubhub/src/views/profile/Profile.jsx +++ b/zubhub_frontend/zubhub/src/views/profile/Profile.jsx @@ -64,16 +64,9 @@ const updateProfile = (e, props, state, newUserNameEL) => { username: username.value, }) .then(res => { - if (!res.id) { - res = Object.keys(res) - .map(key => res[key]) - .join('\n'); - throw new Error(res); - } username.value = ''; return { ...res, ...handleToggleEditProfileModal(state) }; - }) - .catch(error => ({ dialogError: error.message })); + }); } else { return handleToggleEditProfileModal(state); } @@ -135,7 +128,6 @@ function Profile(props) { openEditProfileModal: false, loading: true, profile: {}, - dialogError: null, }); React.useEffect(() => { @@ -150,13 +142,7 @@ function Profile(props) { } }; - const { - results: projects, - profile, - loading, - openEditProfileModal, - dialogError, - } = state; + const { results: projects, profile, loading, openEditProfileModal } = state; if (loading) { return ; @@ -341,16 +327,6 @@ function Profile(props) { aria-labelledby="edit user profile" > Edit User Profile - - {dialogError !== null && ( - - {dialogError} - - )} - {' '} { if (props.values.location.length < 1) { props.validateField('location'); } else { - return props.signup(props).catch(error => { - const messages = JSON.parse(error.message); - if (typeof messages === 'object') { - let non_field_errors; - Object.keys(messages).forEach(key => { - if (key === 'non_field_errors') { - non_field_errors = { error: messages[key][0] }; - } else if (key === 'location') { - props.setFieldTouched('user_location', true, false); - props.setFieldError('user_location', messages[key][0]); - } else { - props.setFieldTouched(key, true, false); - props.setFieldError(key, messages[key][0]); - } - }); - return non_field_errors; - } else { - return { - error: - 'An error occured while performing this action. Please try again later', - }; - } - }); + return props.signup(props); } }; @@ -250,10 +228,7 @@ function Signup(props) { Date Of Birth