Skip to content

Commit

Permalink
Merge pull request #157 from FrontMen/feature/copy-message-previous-week
Browse files Browse the repository at this point in the history
Copy comment from previous week's timesheet
  • Loading branch information
vladPinteaFrontmen authored Jul 8, 2021
2 parents 6be30da + cabfb34 commit 391a61b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 deletions.
24 changes: 21 additions & 3 deletions composables/useTimesheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ export default (employeeId: string, startTimestamp?: number) => {
const timesheetState = computed(() => store.state.timesheets);
const customers = computed(() => store.state.customers);

const timesheetStatus = computed(() =>
timesheetState.value.timesheets[0]
const timesheetStatus = computed(() => {
return timesheetState.value.timesheets[0]
? timesheetState.value.timesheets[0].status
: (recordStatus.NEW as TimesheetStatus)
: (recordStatus.NEW as TimesheetStatus)}
);

const timesheetDenyMessage = computed(() =>
Expand Down Expand Up @@ -60,6 +60,17 @@ export default (employeeId: string, startTimestamp?: number) => {
{ immediate: true }
);

/*
* Gets message from previous week's timesheet when copying.
*/
watch(
() => store.state.timesheets.previousTimesheet,
() => {
message.value = store.state.timesheets.previousTimesheet?.message || message.value;
},
{ immediate: true }
);

const hasRestDayHours = computed(() => {
return timesheet.value.projects.reduce((_, project) => {
return project.values.reduce((acc, value, index) => {
Expand Down Expand Up @@ -121,6 +132,13 @@ export default (employeeId: string, startTimestamp?: number) => {
const prevStartDate = subDays(startDate, 7);
const previousWeek = buildWeek(startOfISOWeek(prevStartDate), []);

// Dispatch getter to update message with message present in previous week.
store.dispatch("timesheets/getPreviousTimesheet", {
startDate: prevStartDate.getTime(),
endDate: startDate.getTime(),
employeeId,
});

const previousWeekTimesheet = createWeeklyTimesheet({
week: previousWeek,
timeRecords: recordsState.value.timeRecords,
Expand Down
16 changes: 16 additions & 0 deletions store/timesheets/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ const actions: ActionTree<TimesheetsStoreState, RootStoreState> = {
commit("setTimesheets", { timesheets });
},

/**
* Action similar to #getTimesheets, but expects to store 1 single timesheet to a different point in store.
* Used in copying previous week, to perpetuate the comment. Payload params mandatory for accuracy in search.
*/
async getPreviousTimesheet(
{ commit },
payload: {
startDate: number;
endDate: number;
employeeId: string;
}
) {
const timesheets = await this.app.$timesheetsService.getTimesheets(payload);
commit("setPreviousTimesheet", { timesheet: timesheets[0] });
},

async getTableData(
{ commit },
payload: {
Expand Down
4 changes: 4 additions & 0 deletions store/timesheets/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ const mutations: MutationTree<TimesheetsStoreState> = {
state.timesheets = payload.timesheets;
},

setPreviousTimesheet: (state, payload: { timesheet: Timesheet }) => {
state.previousTimesheet = payload.timesheet;
},

setTimesheetsTableData: (
state,
payload: { tableData: TimesheetTableData }
Expand Down
1 change: 1 addition & 0 deletions store/timesheets/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export default (): TimesheetsStoreState => ({
selectedEmployeeId: "",
timesheets: [],
timesheetTableData: {} as TimesheetTableData,
previousTimesheet: null,
});
1 change: 1 addition & 0 deletions types/timesheets.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface TimesheetsStoreState {
selectedEmployeeId: string;
timesheets: Timesheet[];
timesheetTableData: TimesheetTableData;
previousTimesheet: Timesheet|null;
}

interface Timesheet {
Expand Down

0 comments on commit 391a61b

Please sign in to comment.