diff --git a/src/views/SimproV2/CreatedProyek/DialogFormProyek.js b/src/views/SimproV2/CreatedProyek/DialogFormProyek.js index 86f06bb..6547f98 100644 --- a/src/views/SimproV2/CreatedProyek/DialogFormProyek.js +++ b/src/views/SimproV2/CreatedProyek/DialogFormProyek.js @@ -16,6 +16,9 @@ import { PROYEK_GET_ID, PROJECT_MILESTONE_WHERE_CUSTOM, PROJECT_PARTICIPANT_WHERE_CUSTOM, + PROJECT_CHECKLIST_WHERE_CUSTOM, + PROJECT_ISSUE_WHERE_CUSTOM, + PROJECT_RISK_WHERE_CUSTOM, PROJECT_APPROVAL_WHERE_CUSTOM, CURRENCY_LIST, } from "../../../const/ApiConst"; @@ -70,14 +73,19 @@ const DialogFormProyek = ({ const [objectives, setObjectives] = useState(""); const [projectIsConsideredSuccessful, setProjectIsConsideredSuccessful] = useState(""); const [participants, setParticipants] = useState([]); + const [checklist, setChecklist] = useState([]); + const [issue, setIssue] = useState([]); const [image, setImage] = useState("") const [availableResources, setAvailableResources] = useState(""); const [milestones, setMilestones] = useState([]); - const [potentialRisks, setPotentialRisks] = useState(""); + const [potentialRisks, setPotentialRisks] = useState([]); const [approval, setApproval] = useState([]); const [testingEnv, setTestingEnv] = useState(""); const [lastIdxParticipants, setLastIdxParticipants] = useState(0); + const [lastIdxChecklists, setLastIdxChecklists] = useState(0); + const [lastIdxIssues, setLastIdxIssues] = useState(0); + const [lastIdxRisks, setLastIdxRisks] = useState(0); const [lastIdxMilestones, setLastIdxMilestones] = useState(0); const [lastIdxApproval, setLastIdxApproval] = useState(0); @@ -108,7 +116,6 @@ const DialogFormProyek = ({ setFinance(val.finance); setObjectives(val.project_objectives ? val.project_objectives : ""); setTestingEnv(val.testing_environment); - setPotentialRisks(val.potential_risk); setProjectIsConsideredSuccessful( val.considered_success_when ? val.considered_success_when : "" ); @@ -141,7 +148,31 @@ const DialogFormProyek = ({ .get(`${PROJECT_PARTICIPANT_WHERE_CUSTOM("proyek_id", id)}`, HEADER) .then((res) => res) .catch((err) => err.response); - setParticipants(result.data.data); + setParticipants(result.data.data); + }; + + const handleGetDataChecklist = async (id) => { + const result = await axios + .get(`${PROJECT_CHECKLIST_WHERE_CUSTOM("proyek_id", id)}`, HEADER) + .then((res) => res) + .catch((err) => err.response); + setChecklist(result.data.data); + }; + + const handleGetDataIssue = async (id) => { + const result = await axios + .get(`${PROJECT_ISSUE_WHERE_CUSTOM("proyek_id", id)}`, HEADER) + .then((res) => res) + .catch((err) => err.response); + setIssue(result.data.data); + }; + + const handleGetDataRisk = async (id) => { + const result = await axios + .get(`${PROJECT_RISK_WHERE_CUSTOM("proyek_id", id)}`, HEADER) + .then((res) => res) + .catch((err) => err.response); + setPotentialRisks(result.data.data); }; const handleGetDataCurrency = async () => { @@ -179,12 +210,15 @@ const DialogFormProyek = ({ setImage(""); setProjectIsConsideredSuccessful(""); setParticipants([]); + setChecklist([]); + setIssue([]); setAvailableResources(""); setMilestones([]); - setPotentialRisks(""); + setPotentialRisks([]); setApproval([]); setTestingEnv(""); setLastIdxParticipants(0); + setLastIdxChecklists(0); setLastIdxMilestones(0); setLastIdxApproval(0); setStep(1); @@ -198,6 +232,9 @@ const DialogFormProyek = ({ if (idTask && idTask > 0) { handleGetdataIdproyek(idTask); handleGetDataParticipants(idTask); + handleGetDataChecklist(idTask); + handleGetDataIssue(idTask); + handleGetDataRisk(idTask); handleGetDataMileStone(idTask); handleGetDataApproval(idTask); } else { @@ -230,13 +267,12 @@ const DialogFormProyek = ({ keterangan: description, project_objectives: objectives, considered_success_when: projectIsConsideredSuccessful, - potential_risk: potentialRisks, testing_environment: testingEnv, currency_symbol: currencySymbol, currency_code: currencyCode, currency_name: currencyName, }; - data.projectCharter = { participants, milestones, approval }; + data.projectCharter = { checklist, issue, potentialRisks, participants, milestones, approval }; data.imageStructureOrg = organization ? organization : null; closeDialog("edit", data); } else { @@ -261,13 +297,12 @@ const DialogFormProyek = ({ keterangan: description, project_objectives: objectives, considered_success_when: projectIsConsideredSuccessful, - potential_risk: potentialRisks, testing_environment: testingEnv, currency_symbol: currencySymbol, currency_code: currencyCode, currency_name: currencyName, }; - data.projectCharter = { participants, milestones, approval }; + data.projectCharter = { checklist, issue, potentialRisks, participants, milestones, approval }; data.imageStructureOrg = organization ? organization : null; closeDialog("add", data); @@ -370,11 +405,87 @@ const DialogFormProyek = ({ setLastIdxParticipants(lastIdxParticipants + 1); }; + const addChecklist = () => { + checklist.push({ + id: lastIdxChecklists + 1, + item: "", + status_exist: "", + }); + setChecklist(checklist); + setLastIdxChecklists(lastIdxChecklists + 1); + }; + + const addIssue = () => { + issue.push({ + id: lastIdxIssues + 1, + description: "", + level_issue: "", + }); + setIssue(issue); + setLastIdxIssues(lastIdxIssues + 1); + }; + + const addRisk = () => { + potentialRisks.push({ + id: lastIdxRisks + 1, + level_risk: "", + description: "", + preventive_risk: "", + }); + setPotentialRisks(potentialRisks); + setLastIdxRisks(lastIdxRisks + 1); + }; + const handleInputChangeParticipants = (e, index) => { const { name, value } = e.target; const newParticipants = [...participants]; newParticipants[index][name] = value; setParticipants(newParticipants); + }; + + const handleInputChangeChecklists = (e, index) => { + if (e === true || e === false) { + const value = e; + const name = "status_exist"; + const newChecklists = [...checklist]; + newChecklists[index][name] = value; + setChecklist(newChecklists); + } else { + const { name, value } = e.target; + const newChecklists = [...checklist]; + newChecklists[index][name] = value; + setChecklist(newChecklists); + } + }; + + const handleInputChangeIssues = (e, index) => { + if (e === 1 || e === 2|| e === 3|| e === 4|| e === 5|| e === 6|| e === 7) { + const value = e; + const name = "level_issue"; + const newIssues = [...issue]; + newIssues[index][name] = value; + setIssue(newIssues); + } else { + const { name, value } = e.target; + const newIssues = [...issue]; + newIssues[index][name] = value; + setIssue(newIssues); + } + }; + + const handleInputChangeRisks = (e, index) => { + if (e === 1 || e === 2 || e === 3 || e === 4 || e === 5 || e === 6 || e === 7) { + const value = e; + const name = "level_risk"; + const newRisks = [...potentialRisks]; + newRisks[index][name] = value; + setPotentialRisks(newRisks); + } else { + const { name, value } = e.target; + const newRisks = [...potentialRisks]; + newRisks[index][name] = value; + setPotentialRisks(newRisks); + } }; const deleteParticipant = (id) => { @@ -385,6 +496,36 @@ const DialogFormProyek = ({ setParticipants(participants.filter((_, i2) => i2 !== id)); } } + }; + + const deleteChecklists = (id) => { + if (checklist && checklist.length > 0) { + let checkIdx = checklist.findIndex((o) => o.id === id); + if (checkIdx > -1) { + checklist.splice(checkIdx, 1); + setChecklist(checklist.filter((_, i2) => i2 !== id)); + } + } + }; + + const deleteIssues = (id) => { + if (issue && issue.length > 0) { + let issueIdx = issue.findIndex((o) => o.id === id); + if (issueIdx > -1) { + issue.splice(issueIdx, 1); + setIssue(issue.filter((_, i2) => i2 !== id)); + } + } + }; + + const deleteRisks = (id) => { + if (potentialRisks && potentialRisks.length > 0) { + let riskIdx = potentialRisks.findIndex((o) => o.id === id); + if (riskIdx > -1) { + potentialRisks.splice(riskIdx, 1); + setPotentialRisks(potentialRisks.filter((_, i2) => i2 !== id)); + } + } }; const addMilestone = () => { @@ -657,7 +798,7 @@ const DialogFormProyek = ({ - + + + + + + + Item + + + Availability + + + Action + + + + + + + +
{RenderChecklist()}
+ +
+ + + + + + + Issu Level + + + Description + + + Action + + + + + + + +
{RenderIssue()}
+ +
Info Dashboard @@ -798,15 +996,17 @@ const DialogFormProyek = ({ Action - - - + + + + +
{RenderParticipants()}
@@ -842,34 +1042,53 @@ const DialogFormProyek = ({ Action - + + +
{RenderMilestones()}
- - - Potential risks - - - - setPotentialRisks(e.target.value)} - placeholder={`List of risks`} - rows={5} - /> - + + + Potential Risk - + + + + Risk Level + + + Description + + + Prevention + + + Action + + + + + + + +
{RenderRisk()}
+ +
Approval @@ -887,12 +1106,14 @@ const DialogFormProyek = ({ Action - - - - + + + + + +
{RenderApproval()}
@@ -902,6 +1123,188 @@ const DialogFormProyek = ({ ) } + const RenderChecklist = () => { + if (checklist.length > 0) { + return checklist.map((item, index) => { + return ( + + + handleInputChangeChecklists(e, index)} + /> + + + + + + + + + + + ); + }); + } else if (checklist.length < 1) { + return ( +
+ No checklist found +
+ ); + } + }; + + const RenderIssue = () => { + if (issue.length > 0) { + return issue.map((item, index) => { + return ( + + + + + + + + + handleInputChangeIssues(e, index)} + /> + + + + + + ); + }); + } else if (issue.length < 1) { + return ( +
+ No Issue found +
+ ); + } + }; + + const RenderRisk = () => { + if (potentialRisks.length > 0) { + return potentialRisks.map((item, index) => { + return ( + + + + + + + + + handleInputChangeRisks(e, index)} + /> + + + handleInputChangeRisks(e, index)} + /> + + + + + + ); + }); + } else if (potentialRisks.length < 1) { + return ( +
+ No Risk found +
+ ); + } + }; + const RenderParticipants = () => { if (participants.length > 0) { return participants.map((item, index) => { @@ -910,7 +1313,7 @@ const DialogFormProyek = ({ handleInputChangeParticipants(e, index)} />