Skip to content

Commit

Permalink
Mark time off responsive (#1710)
Browse files Browse the repository at this point in the history
* added web and mobile form for mark timeoff

* changed the class names priority on tailwindcss

* created new entry buttons component

* fixed the web mark timeoff entry duplicate bug

* fixed the web mark timeoff entry duplicate bug

* Upated Button component size styles to be overrided

* Updated increment decrement time
  • Loading branch information
prasanthchaduvula authored Mar 15, 2024
1 parent 6211ff1 commit 982e77f
Show file tree
Hide file tree
Showing 8 changed files with 714 additions and 216 deletions.
6 changes: 3 additions & 3 deletions app/javascript/src/StyledComponents/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ const DASHED =

const DELETE = "bg-miru-red-400 hover:bg-miru-red-200 text-white";

const SMALL = "px-5/100 py-1vh text-xs font-bold leading-4";
const MEDIUM = "px-10/100 py-1vh text-base font-bold leading-5";
const LARGE = "px-15/100 py-1vh text-xl font-bold leading-7";
const SMALL = "p-2 text-xs font-bold leading-4";
const MEDIUM = "p-2 text-base font-bold leading-5";
const LARGE = "p-2 text-xl font-bold leading-7";

type ButtonProps = {
id?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import React, { useEffect, useState } from "react";

import { format } from "date-fns";
import dayjs from "dayjs";
import { minToHHMM } from "helpers";

import timeoffEntryApi from "apis/timeoff-entry";
Expand Down Expand Up @@ -31,6 +32,7 @@ const TimeoffEntryCard = ({
fetchEntriesOfMonths,
setEditEntryId,
setNewEntryView,
setNewTimeoffEntryView,
} = useTimesheetEntries();
const { id, note, duration, bill_status } = timeoffEntry;
const [isHolidayTimeoffEntry, setIsHolidayTimeoffEntry] =
Expand All @@ -48,7 +50,7 @@ const TimeoffEntryCard = ({
if (timeOffEntry) {
const payload: Payload = {
duration: timeOffEntry.duration,
leave_date: timeOffEntry.leave_date,
leave_date: dayjs(timeoffEntry.leave_date).format("YYYY-MM-DD"),
user_id: selectedEmployeeId,
note,
};
Expand All @@ -64,9 +66,9 @@ const TimeoffEntryCard = ({
};

const handleCardClick = () => {
const isDisableCardClick = true;
if (!isDesktop && !isDisableCardClick) {
if (!isDesktop) {
setEditTimeoffEntryId(id);
setNewTimeoffEntryView(true);
}
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/* eslint-disable @typescript-eslint/no-var-requires */
import React, { useRef } from "react";

import { format } from "date-fns";
import dayjs from "dayjs";
import TextareaAutosize from "react-textarea-autosize";
import { Button, BUTTON_STYLES, TimeInput } from "StyledComponents";

import CustomDatePicker from "common/CustomDatePicker";
import { useTimesheetEntries } from "context/TimesheetEntries";

const DesktopTimeoffForm = ({
isDisplayEditTimeoffEntryForm,
leaveTypeId,
setLeaveTypeId,
holidayId,
setHolidayId,
isHolidayEntry,
isShowHolidayList,
holidayOptions,
note,
setNote,
displayDatePicker,
setDisplayDatePicker,
selectedDate,
handleDateChangeFromDatePicker,
duration,
handleDurationChange,
isValidTimeEntry,
handleSubmit,
}) => {
const datePickerRef = useRef();
const {
leaveTypes,
setNewTimeoffEntryView,
editTimeoffEntryId,
setEditTimeoffEntryId,
} = useTimesheetEntries();

return (
<div className="mt-10 hidden min-h-24 justify-between rounded-lg p-4 shadow-2xl lg:flex">
<div className="w-1/2">
<div className="mb-2 flex w-129 justify-between">
<select
id="leaves"
name="leaves"
value={`${leaveTypeId}`}
className={`h-8 rounded-sm bg-miru-gray-100 ${
isShowHolidayList ? "w-12/25" : "w-full"
}`}
onChange={e => setLeaveTypeId(e?.target?.value || 0)}
>
<option className="text-miru-gray-100" key={0} value={0}>
Leave Type
</option>
{leaveTypes?.length > 0 &&
leaveTypes?.map(leave => (
<option
className="text-miru-gray-100"
key={leave.id}
value={leave.id}
>
{leave.name}
</option>
))}
</select>
{isHolidayEntry() && (
<select
className="ml-4 h-8 w-12/25 rounded-sm bg-miru-gray-100"
id="holidays"
name="holidays"
value={`${holidayId}`}
onChange={e => setHolidayId(Number(e?.target?.value) || 0)}
>
<option className="text-miru-gray-100" key={0} value={0}>
Select Holiday
</option>
{holidayOptions?.length > 0 &&
holidayOptions?.map(holiday => (
<option
className="text-miru-gray-100"
key={holiday.id}
value={holiday.id}
>
{holiday.name}
</option>
))}
</select>
)}
</div>
<TextareaAutosize
cols={60}
name="notes"
placeholder=" Notes"
rows={5}
value={note}
className={`
focus:miru-han-purple-1000 outline-none "h-8" mt-2 w-129 resize-none overflow-y-auto rounded-sm bg-miru-gray-100 px-1
`}
onChange={e => setNote(e.target["value"])}
/>
</div>
<div className="w-60">
<div className="mb-2 flex justify-between">
<div>
{displayDatePicker && (
<div className="relative" ref={datePickerRef}>
<div className="h-100 w-100 absolute top-8 z-10">
<CustomDatePicker
date={dayjs(selectedDate).toDate()}
handleChange={handleDateChangeFromDatePicker}
/>
</div>
</div>
)}
<div
className="formatted-date flex h-8 w-29 items-center justify-center rounded-sm bg-miru-gray-100 p-1 text-sm"
id="formattedDate"
onClick={() => {
setDisplayDatePicker(true);
}}
>
{format(new Date(selectedDate), "do MMM, yyyy")}
</div>
</div>
<TimeInput
className="h-8 w-20 rounded-sm bg-miru-gray-100 p-1 text-sm placeholder:text-miru-gray-1000"
initTime={duration}
name="timeInput"
onTimeChange={handleDurationChange}
/>
</div>
</div>
<div className="max-w-min">
<Button
disabled={!isValidTimeEntry()}
style={BUTTON_STYLES.primary}
className={`mb-1 h-8 w-38 rounded border py-1 px-6 text-xs font-bold uppercase tracking-widest text-white hover:border-transparent ${
!isValidTimeEntry()
? "cursor-not-allowed bg-miru-gray-1000"
: "cursor-pointer bg-miru-han-purple-1000 hover:border-transparent"
}
`}
onClick={handleSubmit}
>
{isDisplayEditTimeoffEntryForm ? "Update" : "Save"}
</Button>
<Button
className="mt-1 h-8 w-38 rounded border border-miru-han-purple-1000 bg-transparent py-1 px-6 text-xs font-bold uppercase tracking-widest text-miru-han-purple-600 hover:border-transparent hover:bg-miru-han-purple-1000 hover:text-white"
style={BUTTON_STYLES.secondary}
onClick={() => {
setNewTimeoffEntryView(false);
if (editTimeoffEntryId) {
setEditTimeoffEntryId(0);
}
}}
>
CANCEL
</Button>
</div>
</div>
);
};

export default DesktopTimeoffForm;
Loading

0 comments on commit 982e77f

Please sign in to comment.