Skip to content

Commit

Permalink
created a constants file
Browse files Browse the repository at this point in the history
  • Loading branch information
sunilk429 committed Nov 30, 2024
1 parent 5727a4d commit 83db091
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
4 changes: 4 additions & 0 deletions task/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const StatusType = {
AVAILABLE: 'AVAILABLE',
ASSIGNED: 'ASSIGNED',
};
1 change: 1 addition & 0 deletions task/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ <h4 class="suggested-users-title">Suggested users</h4>
<div class="loader"></div>
</div>
<script src="/helpers/loadENV.js"></script>
<script src="/task/constants.js"></script>
<script src="/task/script.js"></script>
</div>
</body>
Expand Down
20 changes: 11 additions & 9 deletions task/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -210,15 +210,15 @@ taskForm.onsubmit = async (e) => {
isNoteworthy: isNoteworthy == 'on',
};

if (status === 'ASSIGNED') {
if (status === StatusType.ASSIGNED) {
dataToBeSent.startedOn = new Date() / 1000;
}

if (!endsOn) {
delete dataToBeSent.endsOn;
}

if (status === 'AVAILABLE') {
if (status === StatusType.AVAILABLE) {
delete dataToBeSent.endsOn;
}

Expand Down Expand Up @@ -324,7 +324,7 @@ let stateHandle = () => {
) {
return true;
} else if (
item.value === 'ASSIGNED' &&
item.value === StatusType.ASSIGNED &&
(wasAssigneeSet === false || assigneeEl.value === '')
) {
return true;
Expand Down Expand Up @@ -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';
Expand All @@ -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';
}
}
Expand Down

0 comments on commit 83db091

Please sign in to comment.