-
Notifications
You must be signed in to change notification settings - Fork 77
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
UI/project list page updations #281
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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 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
This file contains 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
This file contains 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,20 +1,62 @@ | ||
import React, { useEffect, useState } from "react"; | ||
|
||
import Select from "react-select"; | ||
import projectApi from "apis/projects"; | ||
import { X } from "phosphor-react"; | ||
|
||
const AddEditProject = ({ editProjectData, setShowProjectModal }) => { | ||
const AddEditProject = ({ setEditProjectData, editProjectData, setShowProjectModal }) => { | ||
|
||
const [client, setClient] = useState<any>(); | ||
const [projectName, setProjectName] = useState<any>(); | ||
const [client, setClient] = useState<any>(null); | ||
const [projectName, setProjectName] = useState<any>(null); | ||
const [projectType, setProjectType] = useState<any>("Billable"); | ||
const [clientList, setClientList] = useState<any>(null); | ||
|
||
useEffect(() => { | ||
const getClientList = async () => { | ||
const data = await projectApi.get(); | ||
setClientList(data.data.clients); | ||
}; | ||
getClientList(); | ||
}, []); | ||
|
||
setClient(editProjectData.clientName); | ||
setProjectName(editProjectData.name); | ||
setProjectType(editProjectData.isBillable ? "Billable" : "Non-Billable"); | ||
}, [editProjectData]); | ||
useEffect(() => { | ||
if (editProjectData) { | ||
if (clientList) { | ||
const client = clientList.filter(client => client.name == editProjectData.client.name); | ||
setClient(client[0].id); | ||
} | ||
setProjectName(editProjectData.name ? editProjectData.name : null); | ||
setProjectType(editProjectData.isBillable ? "Billable" : "Non-Billable"); | ||
} | ||
}, [editProjectData, clientList]); | ||
|
||
const handleEdit = () => { | ||
projectApi.update(editProjectData.id, { | ||
project: { | ||
"client_id": client, | ||
"name": projectName, | ||
"billable": projectType === "Billable" | ||
} | ||
}).then(() => { | ||
setEditProjectData(""); | ||
setShowProjectModal(false); | ||
window.location.reload(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why reload the window? |
||
}); | ||
}; | ||
|
||
const handleSubmit = () => { | ||
projectApi.create({ | ||
project: { | ||
"client_id": client, | ||
"name": projectName, | ||
"billable": projectType === "Billable" | ||
} | ||
}).then(() => { | ||
setEditProjectData(""); | ||
window.location.reload(); | ||
setShowProjectModal(false); | ||
}); | ||
}; | ||
|
||
return ( | ||
<div className="modal__modal main-modal" style={{ background: "rgba(29, 26, 49,0.6)" }}> | ||
|
@@ -25,7 +67,10 @@ const AddEditProject = ({ editProjectData, setShowProjectModal }) => { | |
<div className="modal__close"> | ||
<button | ||
className="modal__button" | ||
onClick={() => setShowProjectModal(false)} | ||
onClick={() => { | ||
setEditProjectData(""); | ||
setShowProjectModal(false); | ||
}} | ||
> | ||
<X size={15} color="#CDD6DF" /> | ||
</button> | ||
|
@@ -40,49 +85,14 @@ const AddEditProject = ({ editProjectData, setShowProjectModal }) => { | |
</label> | ||
</div> | ||
<div className="mt-1"> | ||
<Select | ||
<select | ||
defaultValue={client} | ||
onChange={e => { setClient(e); }} | ||
options={[{ value: "Client1", label: "client1" }, { value: "Client2", label: "client2" }]} | ||
placeholder="Select Client" | ||
isSearchable={true} | ||
components={{ | ||
IndicatorSeparator: () => null | ||
}} | ||
styles={{ | ||
option: (styles, { isSelected }) => ({ | ||
...styles, | ||
backgroundColor: isSelected ? "#F5F7F9" : null, | ||
color: isSelected ? "miru-dark-purple-1000" : null, | ||
height: "40px", | ||
"&:hover": { | ||
backgroundColor: "#F5F7F9" | ||
} | ||
}), | ||
control: (base, state) => ({ | ||
...base, | ||
backgroundColor: "#F5F7F9", | ||
borderColor: "#F5F7F9", | ||
boxShadow: state.isFocused ? "0px" : "0px", | ||
border: state.isFocused ? "0px" : "0px", | ||
"&:hover": { | ||
border: state.isFocused ? "0px" : "0px" | ||
} | ||
}), | ||
placeholder: defaultStyles => ({ | ||
...defaultStyles, | ||
color: "#A5A3AD", | ||
fontWeight: "500", | ||
fontSize: "16px" | ||
}), | ||
menu: base => ({ | ||
...base, | ||
marginTop: 0, | ||
border: 0, | ||
borderRadius: "4px" | ||
}) | ||
}} | ||
/> | ||
className="rounded border-0 block w-full px-2 py-1 bg-miru-gray-100 h-8 font-medium text-sm text-miru-dark-purple-1000 focus:outline-none sm:text-base" | ||
onChange={(e) => setClient(e.target.value)}> | ||
<option value='0'>Select Client</option> | ||
{clientList && | ||
clientList.map(e => <option value={e.id} selected={e.id == client}>{e.name}</option>)} | ||
</select> | ||
</div> | ||
</div> | ||
</div> | ||
|
@@ -104,14 +114,14 @@ const AddEditProject = ({ editProjectData, setShowProjectModal }) => { | |
<div className="mt-1"> | ||
<div className="space-y-4 sm:flex sm:items-center sm:space-y-0 sm:space-x-10"> | ||
<div className="flex items-center"> | ||
<input type="radio" id='billable' name='project_type' defaultChecked={projectType === "Billable"} className="focus:ring-miru-han-purple-1000 h-4 w-4 border-miru-han-purple-1000 text-miru-dark-purple-1000 cursor-pointer" onClick={() => setProjectType("Billable")} /> | ||
<input type="radio" id='billable' name='project_type' defaultChecked={editProjectData ? editProjectData.isBillable : true} className="focus:ring-miru-han-purple-1000 h-4 w-4 border-miru-han-purple-1000 text-miru-dark-purple-1000 cursor-pointer" onClick={() => setProjectType("Billable")} /> | ||
<label htmlFor="billable" className="ml-3 block text-sm font-medium text-miru-dark-purple-1000"> | ||
Billable | ||
</label> | ||
</div> | ||
|
||
<div className="flex items-center"> | ||
<input type="radio" id='non-billable' name='project_type' defaultChecked={projectType === "Non-Billable"} className="focus:ring-miru-han-purple-1000 h-4 w-4 bg--miru-han-purple-1000 border-miru-han-purple-1000 text-miru-dark-purple-1000 cursor-pointer" onClick={() => setProjectType("Non-Billable")} /> | ||
<input type="radio" id='non-billable' name='project_type' defaultChecked={editProjectData ? !editProjectData.isBillable : false} className="focus:ring-miru-han-purple-1000 h-4 w-4 bg--miru-han-purple-1000 border-miru-han-purple-1000 text-miru-dark-purple-1000 cursor-pointer" onClick={() => setProjectType("Non-Billable")} /> | ||
<label htmlFor="non-billable" className="ml-3 block text-sm font-medium text-miru-dark-purple-1000 "> | ||
Non-billable | ||
</label> | ||
|
@@ -123,8 +133,8 @@ const AddEditProject = ({ editProjectData, setShowProjectModal }) => { | |
|
||
<div className="actions mt-4"> | ||
{client && projectName && projectType ? | ||
<button type="submit" className="tracking-widest h-10 w-full flex justify-center py-1 px-4 border border-transparent shadow-sm text-base font-sans font-medium text-miru-white-1000 bg-miru-han-purple-1000 hover:bg-miru-han-purple-600 focus:outline-none rounded cursor-pointer">{editProjectData ? " SAVE CHANGES" : "ADD PROJECT"}</button> | ||
: <button type="submit" className="tracking-widest h-10 w-full flex justify-center py-1 px-4 border border-transparent shadow-sm text-base font-sans font-medium text-miru-white-1000 bg-miru-gray-1000 focus:outline-none rounded cursor-pointer">{editProjectData ? "SAVE CHANGES" : "ADD PROJECT"}</button> | ||
<button type="submit" className="tracking-widest h-10 w-full flex justify-center py-1 px-4 border border-transparent shadow-sm text-base font-sans font-medium text-miru-white-1000 bg-miru-han-purple-1000 hover:bg-miru-han-purple-600 focus:outline-none rounded cursor-pointer" onClick={() => editProjectData ? handleEdit() : handleSubmit()}>{editProjectData ? " SAVE CHANGES" : "ADD PROJECT"}</button> | ||
: <button type="submit" className="tracking-widest h-10 w-full flex justify-center py-1 px-4 border border-transparent shadow-sm text-base font-sans font-medium text-miru-white-1000 bg-miru-gray-1000 focus:outline-none rounded cursor-pointer" disabled>{editProjectData ? "SAVE CHANGES" : "ADD PROJECT"}</button> | ||
} | ||
</div> | ||
</div> | ||
|
This file contains 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
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
why write a function for this?
Also code should be
await projectApi.get() .then(res => {// set state}) .catch(e => {//error handling}
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.
@ajinkyaa Why use
.then
and.catch
withawait
?We should not be using
.then
and.catch
withasync/await
. It defeats the whole purpose of havingasync/await
in the first place.We should write it like this:
cc// @Shruti-Apte