Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Daily total hours #287

Merged
merged 43 commits into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
d731942
checkbox icons added
Feb 17, 2022
c27eca7
refectored
Feb 17, 2022
11029c3
checking if project exist
Feb 17, 2022
ab55ed6
fixed typo
Feb 17, 2022
ee637bc
spec/models/timesheet_entry_spec.rb updated
Feb 17, 2022
47f4e19
initial commit
Feb 20, 2022
0c03eb7
weekly component
Feb 21, 2022
93bf2cd
repo initilized
Feb 28, 2022
8b54847
ui refactored
Mar 8, 2022
7bdaef4
weekly crud added
Mar 16, 2022
daf0e77
conflicts resolved
Mar 16, 2022
f2a827b
removed update_project controller
Mar 17, 2022
cd99d9a
Merge branch 'develop' of https://github.com/saeloun/miru-web into we…
Mar 17, 2022
774f610
removed update_project controller
Mar 17, 2022
01baec2
code refactor
Mar 21, 2022
58d4576
crashing issue fix
Mar 22, 2022
e77c138
try catch added in exios request
Mar 23, 2022
182f2bf
code refactor
Mar 23, 2022
6bf4dcf
DatesInWeek.tsx component added
Mar 23, 2022
a8f778e
minor ui changes
Mar 24, 2022
22990bb
multiple edit entry bug fixes
Mar 25, 2022
7f8db33
font size removed
Mar 25, 2022
d7a85c6
routes conflicts fixed
Mar 25, 2022
e42d3b1
rubocop issue fixed
Mar 25, 2022
aa58b21
removed note validation from rspec
Mar 25, 2022
a8b88c0
large client, project name UI fixed
Mar 25, 2022
c16caa5
invoice spec update on invoice.due_date
Mar 25, 2022
bd39980
fix invoices datacy label typo
Mar 25, 2022
ffc676a
Merge branch 'develop' of https://github.com/saeloun/miru-web into we…
Mar 25, 2022
ce777a7
navbar.js updated
Mar 25, 2022
055e4ef
migration for note added
Mar 28, 2022
f8ff855
interchange save & cancel button in SelectProject.tsx
Mar 28, 2022
84d6f32
Merge branch 'develop' of https://github.com/saeloun/miru-web into mo…
Mar 30, 2022
6723088
initial commit
Mar 31, 2022
b125d2a
calendar added
Apr 12, 2022
34b969f
useEffect for dayInfo to entryList
Apr 13, 2022
171625a
time tracking controller fixed
Apr 13, 2022
d7ac1ca
Akash's changes added
Apr 13, 2022
4096dff
html entity added
Apr 14, 2022
da607b1
daily & monthly sync
Apr 17, 2022
c021a7c
merge with develop
Apr 17, 2022
8500ca4
total daily hours patch added
Apr 18, 2022
29eed70
total daily hours patch added
Apr 18, 2022
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
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