Skip to content

Commit

Permalink
Merge pull request #299 from siemens/feat/create_clearing_request
Browse files Browse the repository at this point in the history
feat(Create_CR): Added feature to change preferred clearing date based on CR priority
  • Loading branch information
hoangnt2 authored Aug 6, 2024
2 parents 908dfda + 28f366e commit ea22ad2
Showing 1 changed file with 34 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import { signOut, useSession } from "next-auth/react"
import { useTranslations } from "next-intl"
import { SelectUsersDialog, ShowInfoOnHover } from "next-sw360"
import { Dispatch, SetStateAction, useCallback, useState } from "react"
import { Dispatch, SetStateAction, useCallback, useEffect, useState } from "react"
import { Alert, Button, Col, Form, Modal, Row } from "react-bootstrap"
import { BsCheck2Square } from "react-icons/bs"
import { ClearingRequestDetails,
Expand All @@ -37,10 +37,12 @@ export default function CreateClearingRequestModal({ show,
projectName }: Props) {
const t = useTranslations('default')
const [message, setMessage] = useState('')
const [minDate, setMinDate] = useState('')
const { data: session, status } = useSession()
const [variant, setVariant] = useState('success')
const [reloadPage, setReloadPage] = useState(false)
const [isDisabled, setIsDisabled] = useState(false)
const [isCritical, setIsCritical] = useState(false)
const [showMessage, setShowMessage] = useState(false)
const [dialogOpenClearingTeam, setDialogOpenClearingTeam] = useState(false)
const [clearingTeamData, setClearingTeamData] = useState<ClearingRequestDataMap>({})
Expand All @@ -52,7 +54,18 @@ export default function CreateClearingRequestModal({ show,
priority: 'LOW',
requestingUserComment: ''
})


useEffect(() => {
const calculateMinDate = () => {
const currentDate = new Date();
if (!isCritical) {
currentDate.setDate(currentDate.getDate() + 21)
}
return currentDate.toISOString().split('T')[0]
}
setMinDate(calculateMinDate());
}, [isCritical])

const updateClearingTeamData = (user: ClearingRequestDataMap) => {
const userEmails = Object.keys(user)
setClearingTeamData(user)
Expand Down Expand Up @@ -118,6 +131,8 @@ export default function CreateClearingRequestModal({ show,

const handleCloseDialog = () => {
setShow(!show)
setMinDate('')
setIsCritical(false)
setIsDisabled(false)
setShowMessage(false)
setCreateClearingRequestPayload({
Expand All @@ -141,11 +156,22 @@ export default function CreateClearingRequestModal({ show,
})
}

const setClearingPriority = (priorityStatus: string) => {
setCreateClearingRequestPayload({
const setClearingPriority = (event: React.ChangeEvent<HTMLInputElement>) => {
setIsCritical(event.target.checked)
if (event.target.checked) {
setCreateClearingRequestPayload({
...createClearingRequestPayload,
priority: priorityStatus
priority: 'CRITICAL',
requestedClearingDate: ''
})
}
else {
setCreateClearingRequestPayload({
...createClearingRequestPayload,
priority: 'LOW',
requestedClearingDate: ''
})
}
}


Expand Down Expand Up @@ -262,6 +288,7 @@ export default function CreateClearingRequestModal({ show,
value={createClearingRequestPayload?.requestedClearingDate ?? ''}
onChange={updateInputField}
disabled={isDisabled}
min={minDate}
required
/>
<div className='form-text'
Expand All @@ -277,11 +304,10 @@ export default function CreateClearingRequestModal({ show,
<Form.Check
type='checkbox'
id='createClearingRequest.priority'
readOnly={true}
name='priority'
checked={isCritical}
style={{marginTop: '1px'}}
onChange={() => setClearingPriority('CRITICAL')}
value={ createClearingRequestPayload.priority}
onChange={setClearingPriority}
disabled={isDisabled}
/>
<Form.Label style={{ fontWeight: 'bold', marginLeft: '10px'}}>
Expand Down

0 comments on commit ea22ad2

Please sign in to comment.