Skip to content

Commit

Permalink
Daily total hours (#287)
Browse files Browse the repository at this point in the history
* checkbox icons added

* checking if project exist

* fixed typo

* spec/models/timesheet_entry_spec.rb updated

* initial commit

* weekly component

* ui refactored

* removed update_project controller

* removed update_project controller

* code refactor

* crashing issue fix

* try catch added in exios request

* code refactor

* DatesInWeek.tsx component added

* minor ui changes

* multiple edit entry bug fixes

* rubocop issue fixed

* removed note validation from rspec

* large client, project name UI fixed

* invoice spec update on invoice.due_date

* fix invoices datacy label typo

fixed root page tests. renamed "invoice-tab" to "invoices-tab"

* migration for note added

* interchange save & cancel button in SelectProject.tsx

* initial commit

* calendar added

* useEffect for dayInfo to entryList

* Akash's changes added

* html entity added

* daily & monthly sync

* total daily hours patch added

Co-authored-by: Mohini Dahiya <mohini@saeloun.com>
  • Loading branch information
Abinash and Mohini Dahiya authored Apr 19, 2022
1 parent c324a43 commit f6391ad
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
33 changes: 24 additions & 9 deletions app/javascript/src/components/time-tracking/Index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ const TimeTracking: React.FC<Iprops> = ({
const [view, setView] = useState<string>("day");
const [newEntryView, setNewEntryView] = useState<boolean>(false);
const [newRowView, setNewRowView] = useState<boolean>(false);
const [selectDate, setSelectDate] = useState<number>(dayjs().weekday());
const [weekDay, setWeekDay] = useState<number>(0);
const [totalHours, setTotalHours] = useState<string>("00:00");
const [selectDate, setSelectDate] = useState<number>(0);
const [weekDay, setWeekDay] = useState<number>(dayjs().weekday());
const [weeklyTotalHours, setWeeklyTotalHours] = useState<string>("00:00");
const [dailyTotalHours, setDailyTotalHours] = useState<number[]>([]);
const [entryList, setEntryList] = useState<object>(entries);
const [selectedFullDate, setSelectedFullDate] = useState<string>(
dayjs().format("YYYY-MM-DD")
Expand All @@ -57,10 +58,15 @@ const TimeTracking: React.FC<Iprops> = ({
}, [weekDay]);

useEffect(() => {
calculateTotalHours();
if (view === "month") return;
parseWeeklyViewData();
calculateTotalHours();
}, [weekDay, entryList]);

useEffect(() => {
setIsWeeklyEditing(false);
}, [view]);

useEffect(() => {
setSelectedFullDate(
dayjs()
Expand All @@ -70,7 +76,8 @@ const TimeTracking: React.FC<Iprops> = ({
}, [selectDate, weekDay]);

const handleWeekTodayButton = () => {
setSelectDate(dayjs().weekday());
setSelectDate(0);
setWeekDay(dayjs().weekday());
};

const handleWeekInfo = () => {
Expand Down Expand Up @@ -113,17 +120,24 @@ const TimeTracking: React.FC<Iprops> = ({

const calculateTotalHours = () => {
let total = 0;
const dailyTotal = [];
for (let weekCounter = 0; weekCounter < 7; weekCounter++) {
const day = dayjs()
.weekday(weekCounter + weekDay)
.format("YYYY-MM-DD");
if (entryList[day]) {
let dayTotal = 0;
entryList[day].forEach(e => {
total += e.duration;
dayTotal += e.duration;
});
dailyTotal.push(minutesToHHMM(dayTotal));
total += dayTotal;
} else {
dailyTotal.push("00:00");
}
}
setTotalHours(minutesToHHMM(total));
setDailyTotalHours(dailyTotal);
setWeeklyTotalHours(minutesToHHMM(total));
};

const handleNextWeek = () => {
Expand All @@ -150,6 +164,7 @@ const TimeTracking: React.FC<Iprops> = ({

const parseWeeklyViewData = () => {
const weekArr = [];
setWeeklyData(weekArr);
for (let weekCounter = 0; weekCounter < 7; weekCounter++) {
const date = dayjs()
.weekday(weekDay + weekCounter)
Expand Down Expand Up @@ -182,7 +197,7 @@ const TimeTracking: React.FC<Iprops> = ({
});
});
}
setWeeklyData(weekArr);
setWeeklyData(() => weekArr);
};

return (
Expand Down Expand Up @@ -265,7 +280,7 @@ const TimeTracking: React.FC<Iprops> = ({
</div>
<div className="flex mr-12">
<p className="text-white mr-2">Total</p>
<p className="text-white font-extrabold">{totalHours}</p>
<p className="text-white font-extrabold">{ view === "week" ? weeklyTotalHours : dailyTotalHours[selectDate] }</p>
</div>
</div>
<DatesInWeek
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const MonthCalender: React.FC<Iprops> = ({ fetchEntries, dayInfo, entryList, sel
let dayInWeekCounter = firstDay;
for (let i = 1; i <= daysInMonth; i++) {
// Ex. date = "2020-01-01"
const date = `${currentYear}-${currentMonthNumber < 9 ? "0" : ""}${currentMonthNumber + 1}-${i < 9 ? "0" : ""}${i}`;
const date = dayjs(`${currentYear}-${currentMonthNumber + 1}-${i}`).format("YYYY-MM-DD");
const totalDuration = entryList[date]?.reduce((acc: number, cv: number) => cv["duration"] + acc, 0);
if (totalDuration) currentWeekTotalHours += totalDuration;
weeksData[dayInWeekCounter] = { date: date, day: i, totalDuration: totalDuration };
Expand Down Expand Up @@ -83,7 +83,6 @@ const MonthCalender: React.FC<Iprops> = ({ fetchEntries, dayInfo, entryList, sel

const handleMonthTodayButton = () => {
handleWeekTodayButton();
setSelectedFullDate(today);
setCurrentMonthNumber(dayjs().month());
setFirstDay(() => dayjs().startOf("month").weekday());
setCurrentYear(dayjs().year());
Expand Down

0 comments on commit f6391ad

Please sign in to comment.