Browse Source

fix PM & Project Participants form

pull/2/head
wahyuun 1 year ago
parent
commit
69c4341209
  1. 56
      src/views/SimproV2/CreatedProyek/DialogFormProyek.js

56
src/views/SimproV2/CreatedProyek/DialogFormProyek.js

@ -333,15 +333,32 @@ const DialogFormProyek = ({
};
const onChangePm = (val) => {
let data = [...dataPM];
var item = data.find((item) => item.id === val);
participants.push({
id: lastIdxParticipants + 1,
title: "PM",
const item = dataPM.find((item) => item.id === val);
const existingParticipant = participants.find((participant) => participant.tittle === "PM");
if (existingParticipant) {
setParticipants((prevParticipants) => {
return prevParticipants.map((participant) => {
if (participant.tittle === "PM") {
return {
...participant,
name: item.name,
};
}
return participant;
});
setParticipants(participants);
});
} else {
setParticipants((prevParticipants) => [
...prevParticipants,
{
id: item.id,
tittle: "PM",
name: item.name,
},
]);
setLastIdxParticipants(lastIdxParticipants + 1);
}
setPic(val);
};
@ -399,7 +416,7 @@ const DialogFormProyek = ({
const addParticipant = () => {
participants.push({
id: lastIdxParticipants + 1,
title: "",
tittle: "",
name: "",
});
setParticipants(participants);
@ -439,6 +456,23 @@ const DialogFormProyek = ({
const handleInputChangeParticipants = (e, index) => {
const { name, value } = e.target;
const existingParticipant = participants.find((participant) => participant.tittle === "PM");
if(value.toLowerCase() === "pm" && name === "tittle" && existingParticipant)
{
alert('PM is already exist!');
setParticipants((prevParticipants) =>
prevParticipants.map((participant, i) => {
if (i === index) {
return {
...participant,
tittle: "",
};
}
return participant;
})
);
return false;
}
const newParticipants = [...participants];
newParticipants[index][name] = value;
setParticipants(newParticipants);
@ -566,7 +600,7 @@ const DialogFormProyek = ({
const addApproval = () => {
approval.push({
id: lastIdxApproval + 1,
title: "",
tittle: "",
name: "",
date: moment(),
});
@ -1321,8 +1355,8 @@ const DialogFormProyek = ({
<Col md={4}>
<Input
type="text"
value={item.tittle ? item.tittle : "-"}
name="title"
value={item.tittle}
name="tittle"
onChange={(e) => handleInputChangeParticipants(e, index)}
/>
</Col>
@ -1421,7 +1455,7 @@ const DialogFormProyek = ({
<Col md={3}>
<Input
type="text"
value={item.tittle ? item.tittle : item.title}
value={item.tittle ? item.tittle : item.tittle}
name="title"
onChange={(e) => handleInputChangeApproval(e, index)}
/>

Loading…
Cancel
Save