-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2483 from ever-co/develop
Release
- Loading branch information
Showing
87 changed files
with
1,334 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { NextResponse } from 'next/server'; | ||
import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; | ||
import { getDayPlansByEmployee } from '@app/services/server/requests'; | ||
import { INextParams } from '@app/interfaces'; | ||
|
||
export async function GET(req: Request, { params }: INextParams) { | ||
const res = new NextResponse(); | ||
const { id } = params; | ||
if (!id) { | ||
return; | ||
} | ||
|
||
const { $res, user, tenantId, organizationId, access_token } = await authenticatedGuard(req, res); | ||
if (!user) return $res('Unauthorized'); | ||
|
||
const response = await getDayPlansByEmployee({ | ||
bearer_token: access_token, | ||
employeeId: id, | ||
organizationId, | ||
tenantId | ||
}); | ||
|
||
return $res(response.data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { ICreateDailyPlan } from '@app/interfaces'; | ||
import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; | ||
import { createPlanRequest, getAllDayPlans } from '@app/services/server/requests'; | ||
import { NextResponse } from 'next/server'; | ||
|
||
export async function POST(req: Request) { | ||
const res = new NextResponse(); | ||
const { $res, user, access_token: bearer_token, tenantId } = await authenticatedGuard(req, res); | ||
|
||
if (!user) return $res('Unauthorized'); | ||
|
||
const body = (await req.json()) as unknown as ICreateDailyPlan; | ||
|
||
const response = await createPlanRequest({ data: body, bearer_token, tenantId }); | ||
|
||
return $res(response.data); | ||
} | ||
|
||
export async function GET(req: Request) { | ||
const res = new NextResponse(); | ||
|
||
const { $res, user, tenantId, organizationId, access_token } = await authenticatedGuard(req, res); | ||
if (!user) return $res('Unauthorized'); | ||
|
||
const response = await getAllDayPlans({ | ||
bearer_token: access_token, | ||
organizationId, | ||
tenantId | ||
}); | ||
|
||
return $res(response.data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { IDailyPlan, ITeamTask } from '@app/interfaces'; | ||
import { formatDayPlanDate } from './date'; | ||
|
||
export const planBadgeContent = (plans: IDailyPlan[], taskId: ITeamTask['id']): string | null => { | ||
// Search a plan that contains a given task | ||
const plan = plans.find((plan) => plan.tasks?.some((task) => task.id === taskId)); | ||
|
||
// If at least one plan have this task | ||
if (plan) { | ||
// Check if the task appears in other plans | ||
const otherPlansWithTask = plans.filter( | ||
(pl) => pl.id !== plan.id && pl.tasks?.some((tsk) => tsk.id === taskId) | ||
); | ||
|
||
// If the task exists in other plans, the its planned many days | ||
if (otherPlansWithTask.length > 0) { | ||
return 'Planned'; | ||
} else { | ||
return `Planned ${formatDayPlanDate(plan.date, 'DD MMM YYYY')}`; | ||
} | ||
// The task does not exist in any plan | ||
} else { | ||
return null; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
'use client'; | ||
|
||
import { useRecoilState } from 'recoil'; | ||
import { useCallback, useEffect } from 'react'; | ||
import { useQuery } from '../useQuery'; | ||
import { dailyPlanFetchingState, dailyPlanListState, userState } from '@app/stores'; | ||
import { createDailyPlanAPI, getAllDayPlansAPI, getDayPlansByEmployeeAPI } from '@app/services/client/api'; | ||
import { ICreateDailyPlan } from '@app/interfaces'; | ||
import { useFirstLoad } from '../useFirstLoad'; | ||
|
||
export function useDailyPlan() { | ||
const [user] = useRecoilState(userState); | ||
|
||
const { loading, queryCall } = useQuery(getDayPlansByEmployeeAPI); | ||
const { loading: getAllDayPlansLoading, queryCall: getAllQueryCall } = useQuery(getAllDayPlansAPI); | ||
const { loading: createDailyPlanLoading, queryCall: createQueryCall } = useQuery(createDailyPlanAPI); | ||
|
||
const [dailyPlan, setDailyPlan] = useRecoilState(dailyPlanListState); | ||
const [dailyPlanFetching, setDailyPlanFetching] = useRecoilState(dailyPlanFetchingState); | ||
const { firstLoadData: firstLoadDailyPlanData, firstLoad } = useFirstLoad(); | ||
|
||
useEffect(() => { | ||
if (firstLoad) { | ||
setDailyPlanFetching(loading); | ||
} | ||
}, [loading, firstLoad, setDailyPlanFetching]); | ||
|
||
const getAllDayPlans = useCallback(() => { | ||
getAllQueryCall().then((response) => { | ||
if (response.data.items.length) { | ||
const { items, total } = response.data; | ||
setDailyPlan({ items, total }); | ||
} | ||
}); | ||
}, [getAllQueryCall, setDailyPlan]); | ||
|
||
const getEmployeeDayPlans = useCallback( | ||
(employeeId: string) => { | ||
queryCall(employeeId).then((response) => { | ||
if (response.data.items.length) { | ||
const { items, total } = response.data; | ||
setDailyPlan({ items, total }); | ||
} | ||
}); | ||
}, | ||
[queryCall, setDailyPlan] | ||
); | ||
|
||
const createDailyPlan = useCallback( | ||
async (data: ICreateDailyPlan) => { | ||
if (user?.tenantId) { | ||
const res = await createQueryCall(data, user?.tenantId || ''); | ||
return res; | ||
} | ||
}, | ||
[createQueryCall, user] | ||
); | ||
|
||
return { | ||
dailyPlan, | ||
setDailyPlan, | ||
dailyPlanFetching, | ||
firstLoadDailyPlanData, | ||
|
||
getAllDayPlans, | ||
getAllDayPlansLoading, | ||
|
||
getEmployeeDayPlans, | ||
loading, | ||
|
||
createDailyPlan, | ||
createDailyPlanLoading | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.