Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,24 @@ export const TeamCalendar: FC<TeamCalendarProps> = (props: TeamCalendarProps) =>
<span className={styles.dateNumber}>{date.getDate()}</span>
<div className={styles.userList}>
{displayedUsers.length > 0
&& displayedUsers.map((user, userIndex) => (
<div
key={`${dateKey}-${user.userId}-${userIndex.toString()}`}
className={classNames(
styles.userItem,
user.status === LeaveStatus.WIPRO_HOLIDAY
? styles.userHoliday
: styles.userLeave,
)}
>
{getUserDisplayName(user)}
</div>
))}
&& displayedUsers.map((user, userIndex) => {
const isHolidayStatus = user.status === LeaveStatus.WIPRO_HOLIDAY

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ maintainability]
Consider extracting the logic for determining isHolidayStatus into a separate function for better readability and maintainability. This will make it easier to update the logic in the future if more holiday statuses are added.

|| user.status === LeaveStatus.HOLIDAY

return (
<div
key={`${dateKey}-${user.userId}-${userIndex.toString()}`}
className={classNames(
styles.userItem,
isHolidayStatus
? styles.userHoliday
: styles.userLeave,
)}
>
{getUserDisplayName(user)}
</div>
)
})}
{overflowCount > 0 && (
<div className={styles.overflowIndicator}>
{`+${overflowCount} more`}
Expand Down
7 changes: 4 additions & 3 deletions src/apps/calendar/src/lib/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { TokenModel } from '~/libs/core'
export enum LeaveStatus {
AVAILABLE = 'AVAILABLE',
LEAVE = 'LEAVE',
WEEKEND = 'WEEKEND',
HOLIDAY = 'HOLIDAY',
WIPRO_HOLIDAY = 'WIPRO_HOLIDAY',
WEEKEND = 'WEEKEND',
}

export type LeaveUpdateStatus = LeaveStatus.AVAILABLE | LeaveStatus.LEAVE
export type LeaveUpdateStatus = LeaveStatus.AVAILABLE | LeaveStatus.LEAVE | LeaveStatus.HOLIDAY

export interface LeaveDate {
date: string
Expand All @@ -21,7 +22,7 @@ export interface TeamLeaveDate {
handle?: string
firstName?: string
lastName?: string
status: LeaveStatus.LEAVE | LeaveStatus.WIPRO_HOLIDAY
status: LeaveStatus.LEAVE | LeaveStatus.HOLIDAY | LeaveStatus.WIPRO_HOLIDAY
}>
}

Expand Down
3 changes: 3 additions & 0 deletions src/apps/calendar/src/lib/utils/calendar.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import { LeaveDate, LeaveStatus } from '../models'

const statusColorMap: Record<LeaveStatus, string> = {
[LeaveStatus.LEAVE]: 'status-leave',
[LeaveStatus.HOLIDAY]: 'status-holiday',
[LeaveStatus.WIPRO_HOLIDAY]: 'status-holiday',
[LeaveStatus.WEEKEND]: 'status-weekend',
[LeaveStatus.AVAILABLE]: 'status-available',
}

const statusLabelMap: Record<LeaveStatus, string> = {
[LeaveStatus.LEAVE]: 'Leave',
[LeaveStatus.HOLIDAY]: 'Personal Holiday',
[LeaveStatus.WIPRO_HOLIDAY]: 'Wipro Holiday',
[LeaveStatus.WEEKEND]: 'Weekend',
[LeaveStatus.AVAILABLE]: 'Available',
Expand All @@ -19,6 +21,7 @@ const statusLabelMap: Record<LeaveStatus, string> = {
export const legendStatusOrder: LeaveStatus[] = [
LeaveStatus.AVAILABLE,
LeaveStatus.LEAVE,
LeaveStatus.HOLIDAY,
LeaveStatus.WIPRO_HOLIDAY,
LeaveStatus.WEEKEND,
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ const PersonalCalendarPage: FC = () => {
}
}, [loadCurrentMonth, selectedDates, updateLeaveDates])

const handleSetAsHoliday = useCallback(async () => {
if (!selectedDates.size) return

setActionError('')
try {
await updateLeaveDates(Array.from(selectedDates), LeaveStatus.HOLIDAY)
setSelectedDates(new Set())
await loadCurrentMonth()
} catch {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ maintainability]
Consider logging the error in the catch block to aid in debugging and monitoring. This will help in identifying the root cause of the failure when updateLeaveDates or loadCurrentMonth fails.

setActionError('Unable to update leave dates. Please try again.')
}
}, [loadCurrentMonth, selectedDates, updateLeaveDates])

const handleSetAsAvailable = useCallback(async () => {
if (!selectedDates.size) return

Expand Down Expand Up @@ -133,6 +146,14 @@ const PersonalCalendarPage: FC = () => {
>
Set as Leave
</Button>
<Button
secondary
variant='warning'
onClick={handleSetAsHoliday}
disabled={!selectedDates.size || isUpdating}
>
Set as Personal Holiday
</Button>
<Button
secondary
onClick={handleSetAsAvailable}
Expand Down
Loading