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

[Feat] Daily plan date range | Filter #2705

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
aa05abc
fix/dailyplan/deleteplan
Innocent-Akim Jul 9, 2024
16b17b3
fix: dailyplan deleteplan
Innocent-Akim Jul 9, 2024
d7824fb
feat: dailyplan deleteplan
Innocent-Akim Jul 10, 2024
888c40b
feat: Daily Plan | Filter by Date range
Innocent-Akim Jul 10, 2024
8ff124a
feat: Daily Plan | Filter by Date range
Innocent-Akim Jul 10, 2024
217c07c
feat: Daily Plan | Filter by Date range
Innocent-Akim Jul 10, 2024
74a2db3
feat: Daily Plan | Filter by Date range check spelling
Innocent-Akim Jul 11, 2024
7465e68
fix/dailyplan/deleteplan
Innocent-Akim Jul 9, 2024
b1d272e
fix: dailyplan deleteplan
Innocent-Akim Jul 9, 2024
5ba6301
feat: dailyplan deleteplan
Innocent-Akim Jul 10, 2024
99b4cef
feat: Daily Plan | Filter by Date range
Innocent-Akim Jul 10, 2024
26e0a1e
feat: Daily Plan | Filter by Date range
Innocent-Akim Jul 10, 2024
dd08115
feat: Daily Plan | Filter by Date range
Innocent-Akim Jul 10, 2024
c8d140b
feat: Daily Plan | Filter by Date range check spelling
Innocent-Akim Jul 11, 2024
fc91a9c
fix: Daily Plan | Filter by Date range
Innocent-Akim Jul 11, 2024
2bebea9
fix: Daily Plan | Filter by Date range
Innocent-Akim Jul 11, 2024
4e338cc
fix: Daily Plan | Filter by Date range
Innocent-Akim Jul 11, 2024
2cc7cd3
fix: Daily Plan | Filter by Date range
Innocent-Akim Jul 11, 2024
1d916b5
feat: Daily Plan | Filter by Date range
Innocent-Akim Jul 11, 2024
8d57172
feat: Daily Plan | Filter by Date range
Innocent-Akim Jul 11, 2024
8f15d5e
fix: Error Daily Plan | Filter by Date range
Innocent-Akim Jul 11, 2024
4225c38
fix: Error Daily Plan | Filter by Date range
Innocent-Akim Jul 11, 2024
8b4e58d
fix: Error Daily Plan | Filter by Date range
Innocent-Akim Jul 11, 2024
91b237b
fix: Error Daily Plan | Filter by Date range
Innocent-Akim Jul 11, 2024
91a4683
fix: Error Daily Plan | Filter by Date range
Innocent-Akim Jul 11, 2024
efac0ee
fix: Error Daily Plan | Filter by Date range
Innocent-Akim Jul 11, 2024
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 @@ -44,7 +44,7 @@ const ManageAssignees: React.FC<IManageAssignees> = ({ memberList, task }) => {
memberList?.filter((member) =>
member.employee
? task?.members.map((item) => item.userId).includes(member.employee?.userId) &&
member.employee?.isActive
member.employee?.isActive
: false
),
[memberList, task?.members]
Expand All @@ -55,7 +55,7 @@ const ManageAssignees: React.FC<IManageAssignees> = ({ memberList, task }) => {
memberList?.filter((member) =>
member.employee
? !task?.members.map((item) => item.userId).includes(member.employee.userId) &&
member.employee?.isActive
member.employee?.isActive
: false
),
[memberList, task?.members]
Expand Down Expand Up @@ -112,9 +112,8 @@ const ManageAssignees: React.FC<IManageAssignees> = ({ memberList, task }) => {
<ProfileInfo
largerProfileInfo={true}
profilePicSrc={member?.employee?.user?.imageUrl}
names={`${member?.employee?.user?.firstName || ''} ${
member?.employee?.user?.lastName || ''
}`}
names={`${member?.employee?.user?.firstName || ''} ${member?.employee?.user?.lastName || ''
}`}
/>
</View>
<View pointerEvents="none">
Expand All @@ -136,9 +135,8 @@ const ManageAssignees: React.FC<IManageAssignees> = ({ memberList, task }) => {
<ProfileInfo
largerProfileInfo={true}
profilePicSrc={member?.employee?.user?.imageUrl}
names={`${member?.employee?.user?.firstName || ''} ${
member?.employee?.user?.lastName || ''
}`}
names={`${member?.employee?.user?.firstName || ''} ${member?.employee?.user?.lastName || ''
}`}
/>
</View>
</TouchableOpacity>
Expand Down
9 changes: 4 additions & 5 deletions apps/web/app/[locale]/permissions/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,10 @@ const Permissions = () => {
<div className="flex flex-col w-[35%] overflow-scroll gap-2 mt-5">
{roles.map((role) => (
<div
className={`flex items-center justify-between w-full py-2 px-5 rounded-xl cursor-pointer ${
selectedRole && selectedRole.id === role.id
? 'bg-primary dark:bg-primary-light text-white'
: ''
}`}
className={`flex items-center justify-between w-full py-2 px-5 rounded-xl cursor-pointer ${selectedRole && selectedRole.id === role.id
? 'bg-primary dark:bg-primary-light text-white'
: ''
}`}
key={role?.id}
onClick={() => {
setSelectedRole(role);
Expand Down
1 change: 1 addition & 0 deletions apps/web/app/helpers/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export const tomorrowDate = moment().add(1, 'days').toDate();
export const yesterdayDate = moment().subtract(1, 'days').toDate();

export const formatDayPlanDate = (dateString: string | Date, format?: string) => {

if (dateString.toString().length > 10) {
dateString = dateString.toString().split('T')[0];
}
Expand Down
1 change: 1 addition & 0 deletions apps/web/app/hooks/features/useDailyPlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ export function useDailyPlan() {
const ascSortedPlans =
profileDailyPlans.items &&
[...profileDailyPlans.items].sort((a, b) => new Date(a.date).getTime() - new Date(b.date).getTime());

const futurePlans = ascSortedPlans?.filter((plan) => {
const planDate = new Date(plan.date);
const today = new Date();
Expand Down
1 change: 1 addition & 0 deletions apps/web/app/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export * from './features/useTaskVersion';

// Daily plan
export * from './features/useDailyPlan';
export * from './useFilterDateRange';

export * from './features/useRefetchData';
export * from './features/useRolePermissions';
Expand Down
56 changes: 56 additions & 0 deletions apps/web/app/hooks/useFilterDateRange.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { IDailyPlan } from '@app/interfaces';
import { dateRangeAllState, dateRangePastState, dateRangeState, filteredAllDataState, filteredDataState, filteredPastDataState, originalAllDataState, originalDataState, originalPastTaskDataState } from '@app/stores';
import { useEffect } from 'react'
import { useRecoilState, useRecoilValue } from 'recoil';

export function useFilterDateRange(itemsData: IDailyPlan[], dataType: 'future' | 'past' | 'all') {
const [dateAllPlan, setDateAllPlan] = useRecoilState(dateRangeAllState);
const [datePastPlan, setDatePastPlan] = useRecoilState(dateRangePastState);
const [dateFuture, setDateFuture] = useRecoilState(dateRangeState);

const [originalAllPlanData, setOriginalAllPlanData] = useRecoilState(originalAllDataState);
const [originalPastPlanData, setOriginalPastPlanData] = useRecoilState(originalPastTaskDataState);
const [originalFuturePlanData, setOriginalFuturePlanData] = useRecoilState(originalDataState);

const filteredAllPlanData = useRecoilValue(
filteredAllDataState
);
const filteredPastPanData = useRecoilValue(
filteredPastDataState

);
const filteredFuturePlanData = useRecoilValue(
filteredDataState

);

useEffect(() => {
if (!itemsData) return;
if (dataType === 'future') {
setOriginalFuturePlanData(itemsData);
}
}, [dateFuture, dataType, itemsData?.length, setOriginalFuturePlanData]);

useEffect(() => {
if (!itemsData) return;
if (dataType === 'all') {
setOriginalAllPlanData(itemsData);
}
}, [dateAllPlan, dataType, itemsData?.length, setOriginalAllPlanData]);

useEffect(() => {
if (!itemsData) return;
if (dataType === 'past') {
setOriginalPastPlanData(itemsData);
}
}, [datePastPlan, dataType, itemsData?.length, setOriginalPastPlanData]);

return {
originalFuturePlanData,
originalPastPlanData,
originalAllPlanData,
filteredFuturePlanData,
filteredPastPanData,
filteredAllPlanData, setDateAllPlan, setDateFuture, setDatePastPlan
};
}
4 changes: 2 additions & 2 deletions apps/web/app/interfaces/IDailyPlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ export interface ICreateDailyPlan extends IDailyPlanBase, IRelationnalEmployee {
taskId?: ITeamTask['id'];
}

export interface IUpdateDailyPlan extends Partial<IDailyPlanBase>, Pick<ICreateDailyPlan, 'employeeId'> {}
export interface IUpdateDailyPlan extends Partial<IDailyPlanBase>, Pick<ICreateDailyPlan, 'employeeId'> { }

export interface IDailyPlanTasksUpdate
extends Pick<ICreateDailyPlan, 'taskId' | 'employeeId'>,
IBasePerTenantAndOrganizationEntity {}
IBasePerTenantAndOrganizationEntity { }

export enum DailyPlanStatusEnum {
OPEN = 'open',
Expand Down
100 changes: 100 additions & 0 deletions apps/web/app/stores/daily-plan.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { atom, selector } from 'recoil';
import { IDailyPlan, PaginationResponse } from '@app/interfaces';
import { DateRange } from 'react-day-picker';
import { addDays, } from 'date-fns';

export const dailyPlanListState = atom<PaginationResponse<IDailyPlan>>({
key: 'dailyPlanListState',
Expand Down Expand Up @@ -44,3 +46,101 @@ export const activeDailyPlanState = selector<IDailyPlan | null>({
return dailyPlans.items.find((plan) => plan.id === activeId) || dailyPlans.items[0] || null;
}
});

const today = new Date();
const oneWeekAgo = new Date();
oneWeekAgo.setDate(today.getDate() - 7);

export const dateRangeState = atom<DateRange | undefined>({
key: 'dateRangeState',
default: ({
from: oneWeekAgo,
to: addDays(today, 3),
}),
})
type daySelectionMode = 'single' | 'multiple' | 'range' | 'default';
export const daySelectionModeState = atom<daySelectionMode | null>({
key: 'mode',
default: 'single',
})

export const dateRangeAllState = atom<DateRange | undefined>({
key: 'dateRangeAllState',
default: ({
from: oneWeekAgo,
to: addDays(today, 3),
}),
})

export const dateRangePastState = atom<DateRange | undefined>({
key: 'dateRangePastPlanState',
default: ({
from: oneWeekAgo,
to: addDays(today, 3),
}),
})

export const originalDataState = atom<IDailyPlan[]>({
key: 'originalDataState',
default: []
})
export const originalAllDataState = atom<IDailyPlan[]>({
key: 'originalAllDataState',
default: []
})
export const originalPastTaskDataState = atom<IDailyPlan[]>({
key: 'originalPastDataState',
default: []
})

function isDateInRange(itemDate: Date, from?: Date, to?: Date): boolean {
if (from && to) {
return itemDate >= from && itemDate <= to;
} else if (from) {
return itemDate >= from;
} else if (to) {
return itemDate <= to;
} else {
return true; // or false, depending on your default logic
}
}
export const filteredDataState = selector({
key: 'filteredDataState',
get: ({ get }) => {
const dateRange = get(dateRangeState);
const data = get(originalDataState);
if (!dateRange || !data.length) return data;
const { from, to } = dateRange;
return data.filter((plan) => {
const itemDate = new Date(plan.date);
return isDateInRange(itemDate, from, to);
});
},
});

export const filteredAllDataState = selector({
key: 'filteredAllDataState',
get: ({ get }) => {
const dateRange = get(dateRangeAllState);
const data = get(originalAllDataState);
if (!dateRange || !data.length) return data;
const { from, to } = dateRange;
return data.filter((plan) => {
const itemDate = new Date(plan.date);
return isDateInRange(itemDate, from, to);
});
},
});
export const filteredPastDataState = selector({
key: 'filteredPastDataState',
get: ({ get }) => {
const dateRange = get(dateRangePastState);
const data = get(originalPastTaskDataState);
if (!dateRange || !data.length) return data;
const { from, to } = dateRange;
return data.filter((plan) => {
const itemDate = new Date(plan.date); // Ensure you're using the correct date field
return isDateInRange(itemDate, from, to);
});
},
});
40 changes: 40 additions & 0 deletions apps/web/lib/components/alert-popup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react'

import {
Popover,
PopoverContent,
PopoverTrigger,
} from "@components/ui/popover"


interface IPopupConfirm {
buttonOpen: any,
open: boolean
}
/**
*
*
* @export
* @param {React.PropsWithChildren<IPopupConfirm>} { children, buttonOpen, open }
* @return {*}
*/
export function AlertPopup({ children, buttonOpen, open }: React.PropsWithChildren<IPopupConfirm>) {
return (
<Popover open={open} >
<PopoverTrigger asChild>
{buttonOpen}
</PopoverTrigger>
<PopoverContent className="min-w-max bg-light--theme-light dark:bg-dark--theme-light outline-none dark:border-gray-600">
<div className="p-4 space-y-4">
<div>
<h4 className="text-lg font-semibold">Delete this plan</h4>
<p className="text-sm text-gray-600">Are you sure you want to delete this plan?</p>
</div>
<div className="flex space-x-4">
{children}
</div>
</div>
</PopoverContent>
</Popover>
)
}
1 change: 1 addition & 0 deletions apps/web/lib/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ export * from './inputs/auth-code-input';

export * from './services/recaptcha';
export * from './copy-tooltip';
export * from './alert-popup'
28 changes: 14 additions & 14 deletions apps/web/lib/features/daily-plan/add-task-to-plan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,21 @@ export function AddTaskToPlan({
const onSubmit = useCallback(async () => {
newPlan
? createDailyPlan({
workTimePlanned: workTimePlanned,
taskId: task.id,
date: new Date(moment(date).format('YYYY-MM-DD')),
status: DailyPlanStatusEnum.OPEN,
tenantId: employee?.tenantId,
employeeId: employee?.employeeId,
organizationId: employee?.organizationId
}).then(() => {
closeModal();
})
workTimePlanned: workTimePlanned,
taskId: task.id,
date: new Date(moment(date).format('YYYY-MM-DD')),
status: DailyPlanStatusEnum.OPEN,
tenantId: employee?.tenantId,
employeeId: employee?.employeeId,
organizationId: employee?.organizationId
}).then(() => {
closeModal();
})
: addTaskToPlan({ employeeId: employee?.employeeId ?? '', taskId: task.id }, selectedPlan?.id ?? '').then(
() => {
closeModal();
}
);
() => {
closeModal();
}
);
}, [
addTaskToPlan,
closeModal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ function MembersList({
{(member?.employee?.user?.image?.thumbUrl ||
member?.employee?.user?.image?.fullUrl ||
member?.employee?.user?.imageUrl) &&
isValidUrl(
member?.employee?.user?.image?.thumbUrl ||
isValidUrl(
member?.employee?.user?.image?.thumbUrl ||
member?.employee?.user?.image?.fullUrl ||
member?.employee?.user?.imageUrl ||
''
) ? (
) ? (
<Avatar
size={36}
className="relative cursor-pointer dark:border-[0.25rem] dark:border-[#26272C]"
Expand Down
Loading
Loading