generated from hackforla/.github-hackforla-base-repo-template
-
-
Notifications
You must be signed in to change notification settings - Fork 97
Allow PMs to edit permitted project fields #795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
drubgrubby
merged 8 commits into
hackforla:development
from
chukalicious:feature/allow-pm-to-edit-project-fields
Dec 16, 2021
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c489e42
added state in editableField.js for user access level to implement co…
chukalicious 61ad08f
modified component variable name to match the component file name. Cr…
chukalicious 0c40c53
added canEdit property to editableField, an array that includes which…
chukalicious d7c7559
cleared logged comments
chukalicious 69b5dab
removed unused vars
chukalicious ac45e1b
added readme document that will be linked to the disabled edit button
chukalicious 933afe8
Added empty table for contacts in the .md file and added a link to it…
chukalicious 80fb8d4
corrected heading in .md file
chukalicious File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,207 +1,237 @@ | ||
| import React, { useState } from 'react'; | ||
| import React from 'react'; | ||
| import '../../sass/ManageProjects.scss'; | ||
| import EditableField from './editableField'; | ||
| import { REACT_APP_CUSTOM_REQUEST_HEADER } from "../../utils/globalSettings"; | ||
| import { REACT_APP_CUSTOM_REQUEST_HEADER } from '../../utils/globalSettings'; | ||
|
|
||
| // Need to hold user state to check which type of user they are and conditionally render editing fields in this component | ||
| //for user level block access to all except for the ones checked | ||
|
|
||
| const EditProjectInfo = ( props ) => { | ||
|
|
||
| const EditProject = (props) => { | ||
| const headerToSend = REACT_APP_CUSTOM_REQUEST_HEADER; | ||
|
|
||
| //const [currentProjectData, setCurrentProjectData] = useState(props.projectToEdit); | ||
|
|
||
| const updateProject = async (projectId, fieldName, fieldValue) => { | ||
|
|
||
| // These field are arrays, but the form makes them comma separated strings, so this adds it back to db as an arrray. | ||
| if (fieldName === 'partners' || fieldName === 'recruitingCategories') { | ||
| if (fieldName === 'partners' || fieldName === 'recruitingCategories') { | ||
| if (!Array.isArray(fieldValue)) { | ||
| fieldValue = fieldValue | ||
| .split(',') | ||
| .filter(x => x !== "") | ||
| .map(y => y.trim()); | ||
| .split(',') | ||
| .filter((x) => x !== '') | ||
| .map((y) => y.trim()); | ||
| } | ||
| } | ||
|
|
||
| // Update database | ||
| const url = `/api/projects/${projectId}`; | ||
| const requestOptions = { | ||
| method: 'PATCH', | ||
| headers: { | ||
| "Content-Type": "application/json", | ||
| "x-customrequired-header": headerToSend | ||
| }, | ||
| body: JSON.stringify({ [fieldName]: fieldValue }) | ||
| method: 'PATCH', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| 'x-customrequired-header': headerToSend, | ||
| }, | ||
| body: JSON.stringify({ [fieldName]: fieldValue }), | ||
| }; | ||
|
|
||
| try { | ||
| const response = await fetch(url, requestOptions); | ||
| const resJson = await response.json(); | ||
| const response = await fetch(url, requestOptions); | ||
| const resJson = await response.json(); | ||
|
|
||
| return resJson; | ||
| return resJson; | ||
| } catch (error) { | ||
| console.log(`update user error: `, error); | ||
| alert("Server not responding. Please try again."); | ||
| console.log(`update user error: `, error); | ||
| alert('Server not responding. Please try again.'); | ||
| } | ||
| }; | ||
|
|
||
|
|
||
| // Add commas to arrays for display | ||
| const partnerDataFormatted = props.projectToEdit.partners.join(", "); | ||
| const recrutingDataFormatted = props.projectToEdit.recruitingCategories.join(", "); | ||
|
|
||
| const partnerDataFormatted = props.projectToEdit.partners.join(', '); | ||
| const recrutingDataFormatted = | ||
| props.projectToEdit.recruitingCategories.join(', '); | ||
|
|
||
| return ( | ||
| <div> | ||
| <div className="project-list-heading">Project: {props.projectToEdit.name}</div> | ||
| <div className="project-list-heading"> | ||
| Project: {props.projectToEdit.name} | ||
| </div> | ||
|
|
||
| <div> | ||
| <EditableField | ||
| fieldData={props.projectToEdit.name} | ||
| fieldName="name" | ||
| <EditableField | ||
| fieldData={props.projectToEdit.name} | ||
| fieldName="name" | ||
| updateProject={updateProject} | ||
| renderUpdatedProj={props.renderUpdatedProj} | ||
| projId={props.projectToEdit._id} | ||
| fieldType="text" | ||
| fieldTitle="Name:" | ||
| accessLevel={props.userAccessLevel} | ||
| canEdit={['admin']} | ||
| /> | ||
| </div> | ||
| <div className="editable-field-div"> | ||
| <EditableField | ||
| fieldData={props.projectToEdit.description} | ||
| fieldName="description" | ||
| <EditableField | ||
| fieldData={props.projectToEdit.description} | ||
| fieldName="description" | ||
| updateProject={updateProject} | ||
| renderUpdatedProj={props.renderUpdatedProj} | ||
| projId={props.projectToEdit._id} | ||
| fieldType="textarea" | ||
| fieldTitle="Description:" | ||
| accessLevel={props.userAccessLevel} | ||
| canEdit={['admin']} | ||
| /> | ||
| </div> | ||
| <div className="editable-field-div"> | ||
| <EditableField | ||
| fieldData={props.projectToEdit.location} | ||
| fieldName="location" | ||
| <EditableField | ||
| fieldData={props.projectToEdit.location} | ||
| fieldName="location" | ||
| updateProject={updateProject} | ||
| renderUpdatedProj={props.renderUpdatedProj} | ||
| projId={props.projectToEdit._id} | ||
| fieldType="text" | ||
| fieldTitle="Location:" | ||
| accessLevel={props.userAccessLevel} | ||
| canEdit={['admin']} | ||
| /> | ||
| </div> | ||
| <div className="editable-field-div"> | ||
| <EditableField | ||
| fieldData={props.projectToEdit.githubIdentifier} | ||
| fieldName="githubIdentifier" | ||
| <EditableField | ||
| fieldData={props.projectToEdit.githubIdentifier} | ||
| fieldName="githubIdentifier" | ||
| updateProject={updateProject} | ||
| renderUpdatedProj={props.renderUpdatedProj} | ||
| projId={props.projectToEdit._id} | ||
| fieldType="text" | ||
| fieldTitle="GitHub Identifier:" | ||
| accessLevel={props.userAccessLevel} | ||
| canEdit={['admin']} | ||
| /> | ||
| </div> | ||
| </div> | ||
| <div className="editable-field-div"> | ||
| <EditableField | ||
| fieldData={props.projectToEdit.githubUrl} | ||
| fieldName="githubUrl" | ||
| <EditableField | ||
| fieldData={props.projectToEdit.githubUrl} | ||
| fieldName="githubUrl" | ||
| updateProject={updateProject} | ||
| renderUpdatedProj={props.renderUpdatedProj} | ||
| projId={props.projectToEdit._id} | ||
| fieldType="text" | ||
| fieldTitle="GitHib URL:" | ||
| accessLevel={props.userAccessLevel} | ||
| canEdit={['admin']} | ||
| /> | ||
| </div> | ||
| <div className="editable-field-div"> | ||
| <EditableField | ||
| fieldData={props.projectToEdit.slackUrl} | ||
| fieldName="slackUrl" | ||
| <EditableField | ||
| fieldData={props.projectToEdit.slackUrl} | ||
| fieldName="slackUrl" | ||
| updateProject={updateProject} | ||
| renderUpdatedProj={props.renderUpdatedProj} | ||
| projId={props.projectToEdit._id} | ||
| fieldType="text" | ||
| fieldTitle="Slack URL:" | ||
| accessLevel={props.userAccessLevel} | ||
| canEdit={['admin']} | ||
| /> | ||
| </div> | ||
| <div className="editable-field-div"> | ||
| <EditableField | ||
| fieldData={props.projectToEdit.googleDriveUrl} | ||
| fieldName="googleDriveUrl" | ||
| <EditableField | ||
| fieldData={props.projectToEdit.googleDriveUrl} | ||
| fieldName="googleDriveUrl" | ||
| updateProject={updateProject} | ||
| renderUpdatedProj={props.renderUpdatedProj} | ||
| projId={props.projectToEdit._id} | ||
| fieldType="text" | ||
| fieldTitle="Google Drive URL:" | ||
| accessLevel={props.userAccessLevel} | ||
| canEdit={['admin', 'user']} | ||
| /> | ||
| </div> | ||
| <div className="editable-field-div"> | ||
| <EditableField | ||
| fieldData={props.projectToEdit.googleDriveId} | ||
| fieldName="googleDriveId" | ||
| <EditableField | ||
| fieldData={props.projectToEdit.googleDriveId} | ||
| fieldName="googleDriveId" | ||
| updateProject={updateProject} | ||
| renderUpdatedProj={props.renderUpdatedProj} | ||
| projId={props.projectToEdit._id} | ||
| fieldType="text" | ||
| fieldTitle="Google Drive ID:" | ||
| accessLevel={props.userAccessLevel} | ||
| canEdit={['admin']} | ||
| /> | ||
| </div> | ||
| <div className="editable-field-div"> | ||
| <EditableField | ||
| fieldData={props.projectToEdit.hflaWebsiteUrl} | ||
| fieldName="hflaWebsiteUrl" | ||
| <EditableField | ||
| fieldData={props.projectToEdit.hflaWebsiteUrl} | ||
| fieldName="hflaWebsiteUrl" | ||
| updateProject={updateProject} | ||
| renderUpdatedProj={props.renderUpdatedProj} | ||
| projId={props.projectToEdit._id} | ||
| fieldType="text" | ||
| fieldTitle="HfLA Website URL:" | ||
| accessLevel={props.userAccessLevel} | ||
| canEdit={['admin']} | ||
| /> | ||
| </div> | ||
| <div className="editable-field-div"> | ||
| <EditableField | ||
| fieldData={props.projectToEdit.videoConferenceLink} | ||
| fieldName="videoConferenceLink" | ||
| <EditableField | ||
| fieldData={props.projectToEdit.videoConferenceLink} | ||
| fieldName="videoConferenceLink" | ||
| updateProject={updateProject} | ||
| renderUpdatedProj={props.renderUpdatedProj} | ||
| projId={props.projectToEdit._id} | ||
| fieldType="text" | ||
| fieldTitle="Video Conference Link:" | ||
| accessLevel={props.userAccessLevel} | ||
| canEdit={['admin', 'user']} | ||
| /> | ||
| </div> | ||
| <div className="editable-field-div"> | ||
| <EditableField | ||
| fieldData={props.projectToEdit.lookingDescription} | ||
| fieldName="lookingDescription" | ||
| <EditableField | ||
| fieldData={props.projectToEdit.lookingDescription} | ||
| fieldName="lookingDescription" | ||
| updateProject={updateProject} | ||
| renderUpdatedProj={props.renderUpdatedProj} | ||
| projId={props.projectToEdit._id} | ||
| fieldType="text" | ||
| fieldTitle="Looking For Description:" | ||
| accessLevel={props.userAccessLevel} | ||
| canEdit={['admin']} | ||
| /> | ||
| </div> | ||
| <div className="editable-field-div"> | ||
| <EditableField | ||
| fieldData={partnerDataFormatted} | ||
| fieldName="partners" | ||
| <EditableField | ||
| fieldData={partnerDataFormatted} | ||
| fieldName="partners" | ||
| updateProject={updateProject} | ||
| renderUpdatedProj={props.renderUpdatedProj} | ||
| projId={props.projectToEdit._id} | ||
| fieldType="text" | ||
| fieldTitle="Partners (comma separated):" | ||
| accessLevel={props.userAccessLevel} | ||
| canEdit={['admin', 'user']} | ||
| /> | ||
| </div> | ||
| </div> | ||
| <div className="editable-field-div"> | ||
| <EditableField | ||
| fieldData={recrutingDataFormatted} | ||
| fieldName="recruitingCategories" | ||
| <EditableField | ||
| fieldData={recrutingDataFormatted} | ||
| fieldName="recruitingCategories" | ||
| updateProject={updateProject} | ||
| renderUpdatedProj={props.renderUpdatedProj} | ||
| projId={props.projectToEdit._id} | ||
| fieldType="text" | ||
| fieldTitle="Recruiting Categories (comma separated):" | ||
| accessLevel={props.userAccessLevel} | ||
| canEdit={['admin']} | ||
| /> | ||
| </div> | ||
|
|
||
|
|
||
| <div><button className="button-back" onClick={props.goSelectProject}>Back to Select Project</button></div> | ||
| </div> | ||
|
|
||
| <div> | ||
| <button className="button-back" onClick={props.goSelectProject}> | ||
| Back to Select Project | ||
| </button> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default EditProjectInfo; | ||
| export default EditProject; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were you an English major? I love that the name of this component bothered you enough to change it here, and in all of the other places that it appears. Miriam Webster would be proud of you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😆 I can barely put two words of English together! But yeah, I find it confusing when the component and the file don't have the same name.