From 83db091913e8de9f6defd9f289fb2965e5ef12bf Mon Sep 17 00:00:00 2001 From: Sunil Kumar Date: Sat, 30 Nov 2024 15:15:07 +0500 Subject: [PATCH] created a constants file --- task/constants.js | 4 ++++ task/index.html | 1 + task/script.js | 20 +++++++++++--------- 3 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 task/constants.js diff --git a/task/constants.js b/task/constants.js new file mode 100644 index 00000000..b27eb797 --- /dev/null +++ b/task/constants.js @@ -0,0 +1,4 @@ +const StatusType = { + AVAILABLE: 'AVAILABLE', + ASSIGNED: 'ASSIGNED', +}; diff --git a/task/index.html b/task/index.html index a5fba571..b0dc59df 100644 --- a/task/index.html +++ b/task/index.html @@ -307,6 +307,7 @@

Suggested users

+ diff --git a/task/script.js b/task/script.js index 68a483cd..a231a7f5 100644 --- a/task/script.js +++ b/task/script.js @@ -80,7 +80,7 @@ const getDaysInEpoch = (remainingDays) => { }; const setDefaultDates = () => { - if (document.getElementById('status').value === 'ASSIGNED') { + if (document.getElementById('status').value === StatusType.ASSIGNED) { const endsOn = document.getElementById('endsOn'); endsOn.value = getFutureDateString(14); endsOn.min = getFutureDateString(1); @@ -97,7 +97,7 @@ function getObjectOfFormData(formId) { const object = {}; const data = new FormData(formId); const isStatusAssigned = - document.getElementById('status').value === 'ASSIGNED'; + document.getElementById('status').value === StatusType.ASSIGNED; data.forEach((value, key) => { if (!Reflect.has(object, key)) { @@ -181,7 +181,7 @@ taskForm.onsubmit = async (e) => { isNoteworthy, } = getObjectOfFormData(taskForm); - if (status === 'ASSIGNED' && !assignee.trim()) { + if (status === StatusType.ASSIGNED && !assignee.trim()) { alert('Assignee can not be empty'); showSubmitLoader(false); document.getElementById('assignee').focus(); @@ -210,7 +210,7 @@ taskForm.onsubmit = async (e) => { isNoteworthy: isNoteworthy == 'on', }; - if (status === 'ASSIGNED') { + if (status === StatusType.ASSIGNED) { dataToBeSent.startedOn = new Date() / 1000; } @@ -218,7 +218,7 @@ taskForm.onsubmit = async (e) => { delete dataToBeSent.endsOn; } - if (status === 'AVAILABLE') { + if (status === StatusType.AVAILABLE) { delete dataToBeSent.endsOn; } @@ -324,7 +324,7 @@ let stateHandle = () => { ) { return true; } else if ( - item.value === 'ASSIGNED' && + item.value === StatusType.ASSIGNED && (wasAssigneeSet === false || assigneeEl.value === '') ) { return true; @@ -401,12 +401,14 @@ const handleDateChange = (event) => { previewDate.innerHTML = !!input.value ? getRemainingDays(input.value) : 14; }; -function handleStatusChange(event = { target: { value: 'AVAILABLE' } }) { +function handleStatusChange( + event = { target: { value: StatusType.AVAILABLE } }, +) { const assignee = document.getElementById('assigneeInput'); const assigneeEl = document.getElementById('assignee'); const endsOnWrapper = document.getElementById('endsOnWrapper'); const featureRadio = document.getElementById('feature'); - if (event.target.value === 'ASSIGNED') { + if (event.target.value === StatusType.ASSIGNED) { setDefaultDates(); assignee.classList.add('show-assignee-field'); assignee.style.display = 'none'; @@ -418,7 +420,7 @@ function handleStatusChange(event = { target: { value: 'AVAILABLE' } }) { document.getElementById('endsOn').value = ''; assigneeEl.value = ''; } - if (event.target.value === 'ASSIGNED' && featureRadio.checked) { + if (event.target.value === StatusType.ASSIGNED && featureRadio.checked) { assignee.style.display = 'flex'; } }