Skip to content

Commit

Permalink
Merge pull request #2102 from ever-co/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
evereq authored Jan 18, 2024
2 parents 0bc6e8f + aff82c1 commit 9015ae5
Show file tree
Hide file tree
Showing 29 changed files with 393 additions and 242 deletions.
41 changes: 22 additions & 19 deletions apps/web/app/[locale]/profile/[memberId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,24 @@ import { ArrowLeft } from 'lib/components/svgs';
import { TaskFilter, Timer, TimerStatus, UserProfileTask, getTimerStatusValue, useTaskFilter } from 'lib/features';
import { MainHeader, MainLayout } from 'lib/layout';
import Link from 'next/link';
import { useMemo, useState } from 'react';
import React, { useCallback, useMemo, useState } from 'react';
import { useTranslations } from 'next-intl';
import stc from 'string-to-color';

import { useRecoilValue } from 'recoil';
import { fullWidthState } from '@app/stores/fullWidth';
import { ActivityFilters } from '@app/constants';
import { ScreenshootTab } from 'lib/features/activity/screenshoots';
import { AppsTab } from 'lib/features/activity/apps';
import { VisitedSitesTab } from 'lib/features/activity/visited-sites';

const Profile = ({ params }: { params: { memberId: string } }) => {
type FilterTab = 'Tasks' | 'Screenshots' | 'Apps' | 'Visited Sites';

const Profile = React.memo(function ProfilePage({ params }: { params: { memberId: string } }) {
const profile = useUserProfilePage();
const { user } = useAuthenticateUser();
const { isTrackingEnabled, activeTeam } = useOrganizationTeams();
const fullWidth = useRecoilValue(fullWidthState);
const [activityFilter, setActivityFilter] = useState<ActivityFilters>(ActivityFilters.TASKS);
const [activityFilter, setActivityFilter] = useState<FilterTab>('Tasks');

const hook = useTaskFilter(profile);
const canSeeActivity = profile.userProfile?.id === user?.id || user?.role?.name?.toUpperCase() == 'MANAGER';
Expand All @@ -39,11 +40,23 @@ const Profile = ({ params }: { params: { memberId: string } }) => {
{ title: JSON.parse(t('pages.profile.BREADCRUMB')) || '', href: `/profile/${params.memberId}` }
];

console.log({ activityFilter });
const activityScreens = {
Tasks: <UserProfileTask profile={profile} tabFiltered={hook} />,
Screenshots: <ScreenshootTab />,
Apps: <AppsTab />,
'Visited Sites': <VisitedSitesTab />
};

const profileIsAuthUser = useMemo(() => profile.isAuthUser, [profile.isAuthUser]);
const hookFilterType = useMemo(() => hook.filterType, [hook.filterType]);

const changeActivityFilter = useCallback(
(filter: FilterTab) => {
setActivityFilter(filter);
},
[setActivityFilter]
);

return (
<>
<MainLayout showTimer={!profileIsAuthUser && isTrackingEnabled}>
Expand Down Expand Up @@ -80,15 +93,15 @@ const Profile = ({ params }: { params: { memberId: string } }) => {
{hook.tab == 'worked' && canSeeActivity && (
<Container fullWidth={fullWidth} className="py-8">
<div className={clsxm('flex justify-start items-center gap-4')}>
{Object.values(ActivityFilters).map((filter: ActivityFilters, i) => (
{Object.keys(activityScreens).map((filter, i) => (
<div key={i} className="flex cursor-pointer justify-start items-center gap-4">
{i !== 0 && <VerticalSeparator />}
<div
className={clsxm(
'text-gray-500',
activityFilter == filter && 'text-black dark:text-white'
)}
onClick={() => setActivityFilter(filter)}
onClick={() => changeActivityFilter(filter as FilterTab)}
>
{filter}
</div>
Expand All @@ -99,22 +112,12 @@ const Profile = ({ params }: { params: { memberId: string } }) => {
)}

<Container fullWidth={fullWidth} className="mb-10">
{hook.tab == 'worked' && activityFilter == ActivityFilters.TASKS ? (
<UserProfileTask profile={profile} tabFiltered={hook} />
) : hook.tab == 'worked' && canSeeActivity && activityFilter == ActivityFilters.SCREENSHOOTS ? (
<ScreenshootTab />
) : hook.tab == 'worked' && canSeeActivity && activityFilter == ActivityFilters.APPS ? (
<AppsTab />
) : hook.tab == 'worked' && canSeeActivity && activityFilter == ActivityFilters.VISITED_SITES ? (
<VisitedSitesTab />
) : (
<UserProfileTask profile={profile} tabFiltered={hook} />
)}
{activityScreens[activityFilter] ?? null}
</Container>
</MainLayout>
</>
);
};
});

function UserProfileDetail({ member }: { member?: OT_Member }) {
const user = useMemo(() => member?.employee.user, [member?.employee.user]);
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/[locale]/task/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const TaskDetails = () => {
{/* <IssueCard related={true} /> */}

{/* <CompletionBlock /> */}
{/* <ActivityBlock /> */}
{/* <TaskActivity /> */}
</div>
</section>
<div className="flex flex-col mt-4 lg:mt-0 3xl:min-w-[24rem] w-full lg:w-[30%]">
Expand Down
17 changes: 9 additions & 8 deletions apps/web/app/api/organization-projects/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ export async function PUT(req: Request, { params }: { params: { id: string } })
if (!user) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });

const { id } = params;

const body = await req.json();

return $res(
await editOrganizationProjectsRequest({
bearer_token: access_token,
id,
datas: body,
tenantId
})
);
const response = await editOrganizationProjectsRequest({
bearer_token: access_token,
id,
datas: body,
tenantId
});

return $res(response.data);
}
20 changes: 9 additions & 11 deletions apps/web/app/api/organization-projects/setting/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ export async function PUT(req: Request, { params }: { params: { id: string } })

const { id } = params;
const body = await req.json();
switch (req.method) {
case 'PUT':
return $res(
await editOrganizationProjectsSettingsRequest({
bearer_token: access_token,
id,
datas: body,
tenantId
})
);
}

const response = await editOrganizationProjectsSettingsRequest({
bearer_token: access_token,
id,
datas: body,
tenantId
});

$res(response.data);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ export async function PUT(req: Request, { params }: { params: { id: string } })
const body = (await req.json()) as IOrganizationTeamEmployeeUpdate;

if (id) {
return $res(
await updateOrganizationTeamEmployeeActiveTaskRequest({
id: id as string,
bearer_token: access_token,
tenantId,
body
})
);
const response = await updateOrganizationTeamEmployeeActiveTaskRequest({
id: id as string,
bearer_token: access_token,
tenantId,
body
});

return $res(response.data);
}
}
36 changes: 18 additions & 18 deletions apps/web/app/api/organization-team-employee/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ export async function PUT(req: Request, { params }: { params: { id: string } })

const { id } = params;

const response = await updateOrganizationTeamEmployeeRequest({
id: id as string,
bearer_token: access_token,
tenantId,
body: body
});

if (id) {
return $res(
await updateOrganizationTeamEmployeeRequest({
id: id as string,
bearer_token: access_token,
tenantId,
body: body
})
);
return $res(response.data);
}
}

Expand All @@ -37,16 +37,16 @@ export async function DELETE(req: Request, { params }: { params: { id: string }
const { employeeId } = searchParams as unknown as { employeeId: string };
const { id } = params;

const response = await deleteOrganizationTeamEmployeeRequest({
id: id as string,
bearer_token: access_token,
tenantId,
organizationId,
employeeId: employeeId as string,
organizationTeamId: teamId
});

if (id) {
return $res(
await deleteOrganizationTeamEmployeeRequest({
id: id as string,
bearer_token: access_token,
tenantId,
organizationId,
employeeId: employeeId as string,
organizationTeamId: teamId
})
);
return $res(response.data);
}
}
34 changes: 15 additions & 19 deletions apps/web/app/api/role-permissions/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@ import { authenticatedGuard } from '@app/services/server/guards/authenticated-gu
import { getRolePermissionsRequest, updateRolePermissionRequest } from '@app/services/server/requests';
import { NextResponse } from 'next/server';

export async function GET(req: Request, { params }: { params: { id: string } }) {
export async function GET(req: Request, { params }: { params: { id: string } }) {
const res = new NextResponse();
const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res);

if (!user) return $res('unauthorized');

const { id } = params;

return $res(
(
await getRolePermissionsRequest({
bearer_token: access_token,
tenantId,
roleId: id as string
})
).data
);
const response = await getRolePermissionsRequest({
bearer_token: access_token,
tenantId,
roleId: id as string
});

return $res(response.data);
}

export async function PUT(req: Request) {
Expand All @@ -29,13 +27,11 @@ export async function PUT(req: Request) {

const body = await req.json();

return $res(
(
await updateRolePermissionRequest({
bearer_token: access_token,
tenantId,
data: body
})
).data
);
const response = await updateRolePermissionRequest({
bearer_token: access_token,
tenantId,
data: body
});

return $res(response.data);
}
38 changes: 18 additions & 20 deletions apps/web/app/api/roles/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,30 @@ export async function GET(req: Request) {
const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res);
if (!user) return $res('unauthorized');

return $res(
(
await getRolesRequest({
bearer_token: access_token,
tenantId
})
).data
);
const response = await getRolesRequest({
bearer_token: access_token,
tenantId
});

return $res(response.data);
}

export async function POST(req: Request) {
const res = new NextResponse();
const { $res, user, access_token, tenantId } = await authenticatedGuard(req, res);

const body = (await req.json()) as IRole;

if (!user) return $res('unauthorized');

return $res(
(
await createRoleRequest({
bearer_token: access_token,
tenantId,
data: {
...body,
tenantId
}
})
).data
);
const response = await createRoleRequest({
bearer_token: access_token,
tenantId,
data: {
...body,
tenantId
}
});

return $res(response.data);
}
8 changes: 4 additions & 4 deletions apps/web/app/hooks/features/useOrganizationTeams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,14 @@ export function useOrganizationTeams() {

const setActiveTeam = useCallback(
(team: (typeof teams)[0]) => {
setActiveTeamIdCookie(team.id);
setOrganizationIdCookie(team.organizationId);
setActiveTeamIdCookie(team?.id);
setOrganizationIdCookie(team?.organizationId);
// This must be called at the end (Update store)
setActiveTeamId(team.id);
setActiveTeamId(team?.id);

// Set Project Id to cookie
// TODO: Make it dynamic when we add Dropdown in Navbar
if (team && team.projects && team.projects.length) {
if (team && team?.projects && team.projects.length) {
setActiveProjectIdCookie(team.projects[0].id);
}
},
Expand Down
Loading

0 comments on commit 9015ae5

Please sign in to comment.