feat: Fetch previous ooo records using DateRangeFilter (#19596)
* teamMates OOO is visible for teamMember * Update packages/features/settings/outOfOffice/CreateOrEditOutOfOfficeModal.tsx Co-authored-by: Omar López <[email protected]> * nit * fixed tests, admin chk reqd for forMembers only * check reqd in case of teamOOO only * datefilter with default and improved search filter * fix preset options * fix ooo tests, due to default date filter * ensure ooo test's wont fail when run on different dates of the month, due to default filter * improvement: instead of 'Date to Year' safer is customRange * added test for non-admin team ooo * show disabled icons instead of notshowing * tests for dateRangeFilters * some more daterangefilter tests * nit * include only fetch prev records in this pr * nit * chore * chore * review comments * chore * update to fix tests * nit * nit * update pagination mode * removed unrelated changes * remove unrelated changes --------- Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: Omar López <[email protected]>
This commit is contained in:
5 files changed
+448
-249
No files matched your search
+1
-1
@@ -3,7 +3,7 @@ import { getTranslate } from "app/_utils";
|
||||
|
||||
import SettingsHeader from "@calcom/features/settings/appDir/SettingsHeader";
|
||||
import CreateNewOutOfOfficeEntryButton from "@calcom/features/settings/outOfOffice/CreateNewOutOfOfficeEntryButton";
|
||||
import { OutOfOfficeEntriesList } from "@calcom/features/settings/outOfOffice/OutOfOfficeEntriesList";
|
||||
import OutOfOfficeEntriesList from "@calcom/features/settings/outOfOffice/OutOfOfficeEntriesList";
|
||||
import { OutOfOfficeToggleGroup } from "@calcom/features/settings/outOfOffice/OutOfOfficeToggleGroup";
|
||||
|
||||
export const generateMetadata = async () =>
|
||||
|
||||
@@ -646,6 +646,161 @@ test.describe("Out of office", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test.describe("Date range filters", () => {
|
||||
test("Default date range filter set to `Last 7 Days`", async ({ page, users }) => {
|
||||
const user = await users.create({ name: `userOne=${Date.now()}` });
|
||||
await user.apiLogin();
|
||||
await page.goto("/settings/my-account/out-of-office");
|
||||
await page.waitForLoadState("domcontentloaded");
|
||||
await page.locator('[data-testid="add-filter-button"]').click();
|
||||
await page.locator('[data-testid="add-filter-item-dateRange"]').click();
|
||||
await expect(
|
||||
page
|
||||
.locator('[data-testid="filter-popover-trigger-dateRange"] span', { hasText: "Last 7 Days" })
|
||||
.nth(0)
|
||||
).toBeVisible();
|
||||
});
|
||||
|
||||
test("Can choose date range presets", async ({ page, users }) => {
|
||||
const user = await users.create({ name: `userOne=${Date.now()}` });
|
||||
await user.apiLogin();
|
||||
await page.goto("/settings/my-account/out-of-office");
|
||||
await page.waitForLoadState("domcontentloaded");
|
||||
await page.locator('[data-testid="add-filter-button"]').click();
|
||||
await page.locator('[data-testid="add-filter-item-dateRange"]').click();
|
||||
await page.locator('[data-testid="add-filter-button"]').click();
|
||||
await page.locator('[data-testid="filter-popover-trigger-dateRange"]').click();
|
||||
|
||||
await expect(page.locator('[data-testid="date-range-options-tdy"]')).toBeVisible(); //Today
|
||||
await expect(page.locator('[data-testid="date-range-options-w"]')).toBeVisible(); //Last 7 Days
|
||||
await expect(page.locator('[data-testid="date-range-options-t"]')).toBeVisible(); //Last 30 Days
|
||||
await expect(page.locator('[data-testid="date-range-options-m"]')).toBeVisible(); //Month to Date
|
||||
await expect(page.locator('[data-testid="date-range-options-y"]')).toBeVisible(); //Year to Date
|
||||
await expect(page.locator('[data-testid="date-range-options-c"]')).toBeVisible(); //Custom
|
||||
});
|
||||
|
||||
test("OOO records are fetched correctly w.r.t their end dates matching the date range filter selected.", async ({
|
||||
page,
|
||||
users,
|
||||
}) => {
|
||||
const member1Name = `member-1-${Date.now()}`;
|
||||
const member2Name = `member-2-${Date.now()}`;
|
||||
const member3Name = `member-3-${Date.now()}`;
|
||||
const teamMatesObj = [{ name: member1Name }, { name: member2Name }];
|
||||
const member3User = await users.create(
|
||||
{ name: member3Name },
|
||||
{
|
||||
hasTeam: true,
|
||||
teamRole: MembershipRole.MEMBER,
|
||||
teammates: teamMatesObj,
|
||||
}
|
||||
);
|
||||
const member1User = users.get().find((user) => user.name === member1Name);
|
||||
const member2User = users.get().find((user) => user.name === member2Name);
|
||||
|
||||
//create OOO for member3, start:currentDate+2Days, end:currentDate+4days (future ooo)
|
||||
await prisma.outOfOfficeEntry.create({
|
||||
data: {
|
||||
start: dayjs().startOf("day").add(2, "days").toDate(),
|
||||
end: dayjs().startOf("day").add(4, "days").toDate(),
|
||||
uuid: uuidv4(),
|
||||
user: { connect: { id: member3User?.id } },
|
||||
createdAt: new Date(),
|
||||
reason: {
|
||||
connect: {
|
||||
id: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
//create OOO for member3, start:currentDate-12Days, end:currentDate-10days (for Last 30 Days)
|
||||
await prisma.outOfOfficeEntry.create({
|
||||
data: {
|
||||
start: dayjs().startOf("day").subtract(12, "days").toDate(),
|
||||
end: dayjs().startOf("day").subtract(10, "days").toDate(),
|
||||
uuid: uuidv4(),
|
||||
user: { connect: { id: member3User?.id } },
|
||||
toUser: { connect: { id: member1User?.id } },
|
||||
createdAt: new Date(),
|
||||
reason: {
|
||||
connect: {
|
||||
id: 2,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
//create OOO for member3, start:currentDate-2Days, end:currentDate-4days (for Last 7 Days)
|
||||
await prisma.outOfOfficeEntry.create({
|
||||
data: {
|
||||
start: dayjs().startOf("day").subtract(4, "days").toDate(),
|
||||
end: dayjs().startOf("day").subtract(2, "days").toDate(),
|
||||
uuid: uuidv4(),
|
||||
user: { connect: { id: member3User?.id } },
|
||||
toUser: { connect: { id: member2User?.id } },
|
||||
createdAt: new Date(),
|
||||
reason: {
|
||||
connect: {
|
||||
id: 2,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await member3User?.apiLogin();
|
||||
const entriesListRespPromise = page.waitForResponse(
|
||||
(response) => response.url().includes("outOfOfficeEntriesList") && response.status() === 200
|
||||
);
|
||||
await page.goto("/settings/my-account/out-of-office");
|
||||
await page.waitForLoadState("domcontentloaded");
|
||||
await entriesListRespPromise;
|
||||
|
||||
//By Default future OOO will be displayed
|
||||
//1 OOO record should be visible for member3, end=currentDate+4days
|
||||
expect(await page.locator('[data-testid^="table-redirect-"]').count()).toBe(1);
|
||||
await expect(page.locator(`data-testid=table-redirect-n-a`).nth(0)).toBeVisible();
|
||||
|
||||
//Default filter 'Last 7 Days' when DateRange Filter is selected
|
||||
await test.step("Default filter - 'Last 7 Days'", async () => {
|
||||
await page.locator('[data-testid="add-filter-button"]').click();
|
||||
await page.locator('[data-testid="add-filter-item-dateRange"]').click();
|
||||
await page.locator('[data-testid="add-filter-button"]').click();
|
||||
const entriesListRespPromise = page.waitForResponse(
|
||||
(response) => response.url().includes("outOfOfficeEntriesList") && response.status() === 200
|
||||
);
|
||||
await page.locator('[data-testid="add-filter-button"]').click();
|
||||
await entriesListRespPromise;
|
||||
|
||||
//1 OOO record should be visible for member3, end=currentDate-4days
|
||||
expect(await page.locator('[data-testid^="table-redirect-"]').count()).toBe(1);
|
||||
await expect(
|
||||
page.locator(`data-testid=table-redirect-${member2User?.username}`).nth(0)
|
||||
).toBeVisible();
|
||||
});
|
||||
|
||||
//Select 'Last 30 Days'
|
||||
await test.step("select 'Last 30 Days'", async () => {
|
||||
await page.locator('[data-testid="filter-popover-trigger-dateRange"]').click();
|
||||
const entriesListRespPromise = page.waitForResponse(
|
||||
(response) => response.url().includes("outOfOfficeEntriesList") && response.status() === 200
|
||||
);
|
||||
await page.locator(`[data-testid="date-range-options-t"]`).click();
|
||||
await page.locator('[data-testid="filter-popover-trigger-dateRange"]').click();
|
||||
await entriesListRespPromise;
|
||||
|
||||
//2 OOO records should be visible end=currentDate-4days, end=currentDate-12days
|
||||
expect(await page.locator('[data-testid^="table-redirect-"]').count()).toBe(2);
|
||||
await expect(
|
||||
page.locator(`data-testid=table-redirect-${member2User?.username}`).nth(0)
|
||||
).toBeVisible();
|
||||
await expect(
|
||||
page.locator(`data-testid=table-redirect-${member1User?.username}`).nth(0)
|
||||
).toBeVisible();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
async function saveAndWaitForResponse(page: Page, expectedStatusCode = 200) {
|
||||
@@ -671,11 +826,11 @@ async function selectDateAndCreateOOO(
|
||||
redirectToUserId?: number,
|
||||
expectedStatusCode = 200,
|
||||
forTeamMember = false,
|
||||
month: "previous-month" | "next-month" = "next-month",
|
||||
month: "previous" | "next" = "next",
|
||||
editMode = false
|
||||
) {
|
||||
const t = await localize("en");
|
||||
await page.locator(`button[name="${month}"]`).click();
|
||||
await page.locator(`button[name="${month}-month"]`).click();
|
||||
await page.locator(`button[name="day"]:text-is("${fromDate}")`).nth(0).click();
|
||||
await page.locator(`button[name="day"]:text-is("${toDate}")`).nth(0).click();
|
||||
editMode
|
||||
|
||||
@@ -1,13 +1,26 @@
|
||||
"use client";
|
||||
|
||||
import { keepPreviousData } from "@tanstack/react-query";
|
||||
import { getCoreRowModel, useReactTable, type ColumnDef } from "@tanstack/react-table";
|
||||
import {
|
||||
createColumnHelper,
|
||||
getCoreRowModel,
|
||||
getFilteredRowModel,
|
||||
useReactTable,
|
||||
} from "@tanstack/react-table";
|
||||
import { Trans } from "next-i18next";
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { useEffect, useMemo, useRef, useState } from "react";
|
||||
import { useFormState } from "react-hook-form";
|
||||
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { DataTable, DataTableToolbar } from "@calcom/features/data-table";
|
||||
import {
|
||||
DataTableWrapper,
|
||||
DataTableToolbar,
|
||||
DataTableProvider,
|
||||
ColumnFilterType,
|
||||
useFilterValue,
|
||||
ZDateRangeFilterValue,
|
||||
DataTableFilters,
|
||||
} from "@calcom/features/data-table";
|
||||
import { getUserAvatarUrl } from "@calcom/lib/getAvatarUrl";
|
||||
import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
@@ -40,7 +53,15 @@ interface OutOfOfficeEntry {
|
||||
canEditAndDelete: boolean;
|
||||
}
|
||||
|
||||
export const OutOfOfficeEntriesList = () => {
|
||||
export default function OutOfOfficeEntriesList() {
|
||||
return (
|
||||
<DataTableProvider>
|
||||
<OutOfOfficeEntriesListContent />
|
||||
</DataTableProvider>
|
||||
);
|
||||
}
|
||||
|
||||
function OutOfOfficeEntriesListContent() {
|
||||
const { t } = useLocale();
|
||||
const tableContainerRef = useRef<HTMLDivElement>(null);
|
||||
const [searchTerm, setSearchTerm] = useState("");
|
||||
@@ -56,12 +77,16 @@ export const OutOfOfficeEntriesList = () => {
|
||||
const searchParams = useCompatSearchParams();
|
||||
const selectedTab = searchParams?.get("type") ?? OutOfOfficeTab.MINE;
|
||||
|
||||
const { data, isPending, fetchNextPage, isFetching, refetch } =
|
||||
const endDateRange = useFilterValue("dateRange", ZDateRangeFilterValue)?.data;
|
||||
|
||||
const { data, isPending, fetchNextPage, isFetching, refetch, hasNextPage } =
|
||||
trpc.viewer.outOfOfficeEntriesList.useInfiniteQuery(
|
||||
{
|
||||
limit: 10,
|
||||
fetchTeamMembersEntries: selectedTab === OutOfOfficeTab.TEAM,
|
||||
searchTerm,
|
||||
endDateFilterStartRange: endDateRange?.startDate ?? undefined,
|
||||
endDateFilterEndRange: endDateRange?.endDate ?? undefined,
|
||||
},
|
||||
{
|
||||
getNextPageParam: (lastPage) => lastPage.nextCursor,
|
||||
@@ -79,214 +104,216 @@ export const OutOfOfficeEntriesList = () => {
|
||||
isPending || isFetching ? new Array(5).fill(null) : data?.pages?.flatMap((page) => page.rows) ?? [],
|
||||
[data, selectedTab, isPending, isFetching, searchTerm]
|
||||
) as OutOfOfficeEntry[];
|
||||
const totalFetched = flatData.length;
|
||||
|
||||
const memoColumns = useMemo(() => {
|
||||
const columns: ColumnDef<OutOfOfficeEntry>[] = [];
|
||||
if (selectedTab === OutOfOfficeTab.TEAM) {
|
||||
columns.push({
|
||||
id: "member",
|
||||
header: `Member`,
|
||||
size: 300,
|
||||
const columnHelper = createColumnHelper<OutOfOfficeEntry>();
|
||||
return [
|
||||
columnHelper.accessor((row) => row, {
|
||||
id: "dateRange",
|
||||
header: t("date_range"),
|
||||
enableColumnFilter: true,
|
||||
enableSorting: false,
|
||||
cell: () => null,
|
||||
filterFn: () => true,
|
||||
meta: {
|
||||
filter: {
|
||||
type: ColumnFilterType.DATE_RANGE,
|
||||
dateRangeOptions: {
|
||||
range: "past",
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
...(selectedTab === OutOfOfficeTab.TEAM
|
||||
? [
|
||||
columnHelper.display({
|
||||
id: "member",
|
||||
header: `Member`,
|
||||
size: 300,
|
||||
cell: ({ row }) => {
|
||||
if (!row.original || !row.original.user || isPending || isFetching) {
|
||||
return <SkeletonText className="h-8 w-full" />;
|
||||
}
|
||||
const { avatarUrl, username, email, name } = row.original.user;
|
||||
const memberName =
|
||||
name ||
|
||||
(() => {
|
||||
const emailName = email.split("@")[0];
|
||||
return emailName.charAt(0).toUpperCase() + emailName.slice(1);
|
||||
})();
|
||||
return (
|
||||
<div className="flex items-center gap-2">
|
||||
<Avatar
|
||||
size="sm"
|
||||
alt={username || email}
|
||||
imageSrc={getUserAvatarUrl({
|
||||
avatarUrl,
|
||||
})}
|
||||
/>
|
||||
<div className="">
|
||||
<div
|
||||
data-testid={`ooo-member-${username}-username`}
|
||||
className="text-emphasis text-sm font-medium leading-none">
|
||||
{memberName}
|
||||
</div>
|
||||
<div
|
||||
data-testid={`ooo-member-${username}-email`}
|
||||
className="text-subtle mt-1 text-sm leading-none">
|
||||
{email}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
}),
|
||||
]
|
||||
: []),
|
||||
columnHelper.display({
|
||||
id: "outOfOffice",
|
||||
header: `${t("out_of_office")} (${totalRowCount})`,
|
||||
size: selectedTab === OutOfOfficeTab.TEAM ? 370 : 660,
|
||||
cell: ({ row }) => {
|
||||
if (!row.original || !row.original.user || isPending || isFetching) {
|
||||
return <SkeletonText className="h-8 w-full" />;
|
||||
}
|
||||
const { avatarUrl, username, email, name } = row.original.user;
|
||||
const memberName =
|
||||
name ||
|
||||
(() => {
|
||||
const emailName = email.split("@")[0];
|
||||
return emailName.charAt(0).toUpperCase() + emailName.slice(1);
|
||||
})();
|
||||
const item = row.original;
|
||||
return (
|
||||
<div className="flex items-center gap-2">
|
||||
<Avatar
|
||||
size="sm"
|
||||
alt={username || email}
|
||||
imageSrc={getUserAvatarUrl({
|
||||
avatarUrl,
|
||||
})}
|
||||
/>
|
||||
<div className="">
|
||||
<>
|
||||
{row.original && !isPending && !isFetching ? (
|
||||
<div
|
||||
data-testid={`ooo-member-${username}-username`}
|
||||
className="text-emphasis text-sm font-medium leading-none">
|
||||
{memberName}
|
||||
className="flex flex-row justify-between p-2"
|
||||
data-testid={`table-redirect-${item.toUser?.username || "n-a"}`}>
|
||||
<div className="flex flex-row items-center">
|
||||
<div className="flex h-10 w-10 items-center justify-center rounded-full bg-gray-50">
|
||||
{item?.reason?.emoji || "🏝️"}
|
||||
</div>
|
||||
|
||||
<div className="ml-2 flex flex-col">
|
||||
<p className="px-2 font-bold">
|
||||
{dayjs.utc(item.start).format("ll")} - {dayjs.utc(item.end).format("ll")}
|
||||
</p>
|
||||
<p className="px-2">
|
||||
{item.toUser?.username ? (
|
||||
<Trans
|
||||
i18nKey="ooo_forwarding_to"
|
||||
values={{
|
||||
username: item.toUser?.username,
|
||||
}}
|
||||
components={{
|
||||
span: <span className="text-subtle font-bold" />,
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<>{t("ooo_not_forwarding")}</>
|
||||
)}
|
||||
</p>
|
||||
{item.notes && (
|
||||
<p className="px-2">
|
||||
<span className="text-subtle">{t("notes")}: </span>
|
||||
<span data-testid={`ooo-entry-note-${item.toUser?.username || "n-a"}`}>
|
||||
{item.notes}
|
||||
</span>
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
data-testid={`ooo-member-${username}-email`}
|
||||
className="text-subtle mt-1 text-sm leading-none">
|
||||
{email}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<SkeletonText className="h-8 w-full" />
|
||||
)}
|
||||
</>
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
columns.push({
|
||||
id: "outOfOffice",
|
||||
header: `${t("out_of_office")} (${totalRowCount})`,
|
||||
size: selectedTab === OutOfOfficeTab.TEAM ? 370 : 660,
|
||||
cell: ({ row }) => {
|
||||
const item = row.original;
|
||||
return (
|
||||
<>
|
||||
{row.original && !isPending && !isFetching ? (
|
||||
<div
|
||||
className="flex flex-row justify-between p-2"
|
||||
data-testid={`table-redirect-${item.toUser?.username || "n-a"}`}>
|
||||
<div className="flex flex-row items-center">
|
||||
<div className="flex h-10 w-10 items-center justify-center rounded-full bg-gray-50">
|
||||
{item?.reason?.emoji || "🏝️"}
|
||||
</div>
|
||||
|
||||
<div className="ml-2 flex flex-col">
|
||||
<p className="px-2 font-bold">
|
||||
{dayjs.utc(item.start).format("ll")} - {dayjs.utc(item.end).format("ll")}
|
||||
</p>
|
||||
<p className="px-2">
|
||||
{item.toUser?.username ? (
|
||||
<Trans
|
||||
i18nKey="ooo_forwarding_to"
|
||||
values={{
|
||||
username: item.toUser?.username,
|
||||
}}
|
||||
components={{
|
||||
span: <span className="text-subtle font-bold" />,
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<>{t("ooo_not_forwarding")}</>
|
||||
)}
|
||||
</p>
|
||||
{item.notes && (
|
||||
<p className="px-2">
|
||||
<span className="text-subtle">{t("notes")}: </span>
|
||||
<span data-testid={`ooo-entry-note-${item.toUser?.username || "n-a"}`}>
|
||||
{item.notes}
|
||||
</span>
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
}),
|
||||
columnHelper.display({
|
||||
id: "actions",
|
||||
size: 90,
|
||||
cell: ({ row }) => {
|
||||
const item = row.original;
|
||||
return (
|
||||
<>
|
||||
{row.original && !isPending && !isFetching ? (
|
||||
<div className="flex flex-row items-center justify-end gap-x-2">
|
||||
<Tooltip content={t("edit")}>
|
||||
<Button
|
||||
className="self-center rounded-lg border"
|
||||
type="button"
|
||||
color="secondary"
|
||||
variant="icon"
|
||||
data-testid={`ooo-edit-${item.toUser?.username || "n-a"}`}
|
||||
StartIcon="pencil"
|
||||
onClick={() => {
|
||||
const offset = dayjs().utcOffset();
|
||||
const outOfOfficeEntryData: BookingRedirectForm = {
|
||||
uuid: item.uuid,
|
||||
dateRange: {
|
||||
startDate: dayjs(item.start).subtract(offset, "minute").toDate(),
|
||||
endDate: dayjs(item.end).subtract(offset, "minute").startOf("d").toDate(),
|
||||
},
|
||||
offset,
|
||||
toTeamUserId: item.toUserId,
|
||||
reasonId: item.reason?.id ?? 1,
|
||||
notes: item.notes ?? undefined,
|
||||
forUserId: item.user?.id || null,
|
||||
forUserName:
|
||||
item.user?.name ||
|
||||
(item.user?.email &&
|
||||
(() => {
|
||||
const emailName = item.user?.email.split("@")[0];
|
||||
return emailName.charAt(0).toUpperCase() + emailName.slice(1);
|
||||
})()),
|
||||
forUserAvatar: item.user?.avatarUrl,
|
||||
toUserName: item.toUser?.name || item.toUser?.username,
|
||||
};
|
||||
editOutOfOfficeEntry(outOfOfficeEntryData);
|
||||
}}
|
||||
disabled={isPending || isFetching || !item.canEditAndDelete}
|
||||
/>
|
||||
</Tooltip>
|
||||
<Tooltip content={t("delete")}>
|
||||
<Button
|
||||
className="self-center rounded-lg border"
|
||||
type="button"
|
||||
color="destructive"
|
||||
variant="icon"
|
||||
disabled={
|
||||
deleteOutOfOfficeEntryMutation.isPending ||
|
||||
isPending ||
|
||||
isFetching ||
|
||||
!item.canEditAndDelete
|
||||
}
|
||||
StartIcon="trash-2"
|
||||
data-testid={`ooo-delete-${item.toUser?.username || "n-a"}`}
|
||||
onClick={() => {
|
||||
deleteOutOfOfficeEntryMutation.mutate({
|
||||
outOfOfficeUid: item.uuid,
|
||||
userId: selectedTab === OutOfOfficeTab.TEAM ? item.user?.id : undefined,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<SkeletonText className="h-8 w-full" />
|
||||
)}
|
||||
</>
|
||||
);
|
||||
},
|
||||
});
|
||||
columns.push({
|
||||
id: "actions",
|
||||
size: 90,
|
||||
cell: ({ row }) => {
|
||||
const item = row.original;
|
||||
return (
|
||||
<>
|
||||
{row.original && !isPending && !isFetching ? (
|
||||
<div className="flex flex-row items-center justify-end gap-x-2">
|
||||
<Tooltip content={t("edit")}>
|
||||
<Button
|
||||
className="self-center rounded-lg border"
|
||||
type="button"
|
||||
color="secondary"
|
||||
variant="icon"
|
||||
data-testid={`ooo-edit-${item.toUser?.username || "n-a"}`}
|
||||
StartIcon="pencil"
|
||||
onClick={() => {
|
||||
const offset = dayjs().utcOffset();
|
||||
const outOfOfficeEntryData: BookingRedirectForm = {
|
||||
uuid: item.uuid,
|
||||
dateRange: {
|
||||
startDate: dayjs(item.start).subtract(offset, "minute").toDate(),
|
||||
endDate: dayjs(item.end).subtract(offset, "minute").startOf("d").toDate(),
|
||||
},
|
||||
offset,
|
||||
toTeamUserId: item.toUserId,
|
||||
reasonId: item.reason?.id ?? 1,
|
||||
notes: item.notes ?? undefined,
|
||||
forUserId: item.user?.id || null,
|
||||
forUserName:
|
||||
item.user?.name ||
|
||||
(item.user?.email &&
|
||||
(() => {
|
||||
const emailName = item.user?.email.split("@")[0];
|
||||
return emailName.charAt(0).toUpperCase() + emailName.slice(1);
|
||||
})()),
|
||||
forUserAvatar: item.user?.avatarUrl,
|
||||
toUserName: item.toUser?.name || item.toUser?.username,
|
||||
};
|
||||
editOutOfOfficeEntry(outOfOfficeEntryData);
|
||||
}}
|
||||
disabled={isPending || isFetching || !item.canEditAndDelete}
|
||||
/>
|
||||
</Tooltip>
|
||||
<Tooltip content={t("delete")}>
|
||||
<Button
|
||||
className="self-center rounded-lg border"
|
||||
type="button"
|
||||
color="destructive"
|
||||
variant="icon"
|
||||
disabled={
|
||||
deleteOutOfOfficeEntryMutation.isPending ||
|
||||
isPending ||
|
||||
isFetching ||
|
||||
!item.canEditAndDelete
|
||||
}
|
||||
StartIcon="trash-2"
|
||||
data-testid={`ooo-delete-${item.toUser?.username || "n-a"}`}
|
||||
onClick={() => {
|
||||
deleteOutOfOfficeEntryMutation.mutate({
|
||||
outOfOfficeUid: item.uuid,
|
||||
userId: selectedTab === OutOfOfficeTab.TEAM ? item.user?.id : undefined,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
</Tooltip>
|
||||
</div>
|
||||
) : (
|
||||
<SkeletonText className="h-8 w-full" />
|
||||
)}
|
||||
</>
|
||||
);
|
||||
},
|
||||
});
|
||||
return columns;
|
||||
) : (
|
||||
<SkeletonText className="h-8 w-full" />
|
||||
)}
|
||||
</>
|
||||
);
|
||||
},
|
||||
}),
|
||||
];
|
||||
}, [selectedTab, isPending, isFetching]);
|
||||
|
||||
const fetchMoreOnBottomReached = useCallback(
|
||||
(containerRefElement?: HTMLDivElement | null) => {
|
||||
if (containerRefElement) {
|
||||
const { scrollHeight, scrollTop, clientHeight } = containerRefElement;
|
||||
if (scrollHeight - scrollTop - clientHeight < 100 && !isFetching && totalFetched < totalRowCount) {
|
||||
fetchNextPage();
|
||||
}
|
||||
if (isFetching) {
|
||||
containerRefElement.classList.add("cursor-wait");
|
||||
} else {
|
||||
containerRefElement.classList.remove("cursor-wait");
|
||||
}
|
||||
}
|
||||
},
|
||||
[fetchNextPage, isFetching, totalFetched, totalRowCount]
|
||||
);
|
||||
|
||||
const table = useReactTable({
|
||||
data: flatData,
|
||||
columns: memoColumns,
|
||||
initialState: {
|
||||
columnVisibility: {
|
||||
dateRange: false,
|
||||
},
|
||||
},
|
||||
enableRowSelection: false,
|
||||
debugTable: true,
|
||||
manualPagination: true,
|
||||
getCoreRowModel: getCoreRowModel(),
|
||||
getFilteredRowModel: getFilteredRowModel(),
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
fetchMoreOnBottomReached(tableContainerRef.current);
|
||||
}, [fetchMoreOnBottomReached]);
|
||||
|
||||
const deleteOutOfOfficeEntryMutation = trpc.viewer.outOfOfficeEntryDelete.useMutation({
|
||||
onSuccess: () => {
|
||||
showToast(t("success_deleted_entry_out_of_office"), "success");
|
||||
@@ -300,60 +327,67 @@ export const OutOfOfficeEntriesList = () => {
|
||||
|
||||
return (
|
||||
<>
|
||||
{data === null ||
|
||||
(data?.pages?.length !== 0 && data?.pages[0].meta.totalRowCount === 0 && searchTerm === "") ||
|
||||
(data === undefined && !isPending) ? (
|
||||
<EmptyScreen
|
||||
className="mt-6"
|
||||
headline={selectedTab === OutOfOfficeTab.TEAM ? t("ooo_team_empty_title") : t("ooo_empty_title")}
|
||||
description={
|
||||
selectedTab === OutOfOfficeTab.TEAM ? t("ooo_team_empty_description") : t("ooo_empty_description")
|
||||
}
|
||||
buttonRaw={<CreateNewOutOfOfficeEntryButton size="sm" />}
|
||||
customIcon={
|
||||
<div className="mt-4 h-[102px]">
|
||||
<div className="flex h-full flex-col items-center justify-center p-2 md:mt-0 md:p-0">
|
||||
<div className="relative">
|
||||
<div className="dark:bg-darkgray-50 absolute -left-3 -top-3 -z-20 h-[70px] w-[70px] -rotate-[24deg] rounded-3xl border-2 border-[#e5e7eb] p-8 opacity-40 dark:opacity-80">
|
||||
<div className="w-12" />
|
||||
</div>
|
||||
<div className="dark:bg-darkgray-50 absolute -top-3 left-3 -z-10 h-[70px] w-[70px] rotate-[24deg] rounded-3xl border-2 border-[#e5e7eb] p-8 opacity-60 dark:opacity-90">
|
||||
<div className="w-12" />
|
||||
</div>
|
||||
<div className="dark:bg-darkgray-50 text-inverted relative z-0 flex h-[70px] w-[70px] items-center justify-center rounded-3xl border-2 border-[#e5e7eb] bg-white">
|
||||
<Icon name="clock" size={28} />
|
||||
<div className="dark:bg-darkgray-50 absolute right-4 top-5 h-[12px] w-[12px] rotate-[56deg] bg-white text-lg font-bold" />
|
||||
<span className="absolute right-4 top-3 font-sans text-sm font-extrabold">z</span>
|
||||
<DataTableWrapper
|
||||
testId="ooo-list-data-table"
|
||||
hideHeader={selectedTab === OutOfOfficeTab.MINE}
|
||||
table={table}
|
||||
isPending={isPending}
|
||||
hasNextPage={hasNextPage}
|
||||
fetchNextPage={fetchNextPage}
|
||||
isFetching={isFetching}
|
||||
totalRowCount={totalRowCount}
|
||||
tableContainerRef={tableContainerRef}
|
||||
paginationMode="infinite"
|
||||
ToolbarLeft={<DataTableToolbar.SearchBar table={table} onSearch={(value) => setSearchTerm(value)} />}
|
||||
ToolbarRight={
|
||||
<>
|
||||
<DataTableFilters.AddFilterButton table={table} />
|
||||
<DataTableFilters.ActiveFilters table={table} />
|
||||
<DataTableFilters.ClearFiltersButton />
|
||||
</>
|
||||
}
|
||||
EmptyView={
|
||||
<EmptyScreen
|
||||
className="mt-6"
|
||||
headline={selectedTab === OutOfOfficeTab.TEAM ? t("ooo_team_empty_title") : t("ooo_empty_title")}
|
||||
description={
|
||||
selectedTab === OutOfOfficeTab.TEAM
|
||||
? t("ooo_team_empty_description")
|
||||
: t("ooo_empty_description")
|
||||
}
|
||||
buttonRaw={<CreateNewOutOfOfficeEntryButton size="sm" />}
|
||||
customIcon={
|
||||
<div className="mt-4 h-[102px]">
|
||||
<div className="flex h-full flex-col items-center justify-center p-2 md:mt-0 md:p-0">
|
||||
<div className="relative">
|
||||
<div className="dark:bg-darkgray-50 absolute -left-3 -top-3 -z-20 h-[70px] w-[70px] -rotate-[24deg] rounded-3xl border-2 border-[#e5e7eb] p-8 opacity-40 dark:opacity-80">
|
||||
<div className="w-12" />
|
||||
</div>
|
||||
<div className="dark:bg-darkgray-50 absolute -top-3 left-3 -z-10 h-[70px] w-[70px] rotate-[24deg] rounded-3xl border-2 border-[#e5e7eb] p-8 opacity-60 dark:opacity-90">
|
||||
<div className="w-12" />
|
||||
</div>
|
||||
<div className="dark:bg-darkgray-50 text-inverted relative z-0 flex h-[70px] w-[70px] items-center justify-center rounded-3xl border-2 border-[#e5e7eb] bg-white">
|
||||
<Icon name="clock" size={28} />
|
||||
<div className="dark:bg-darkgray-50 absolute right-4 top-5 h-[12px] w-[12px] rotate-[56deg] bg-white text-lg font-bold" />
|
||||
<span className="absolute right-4 top-3 font-sans text-sm font-extrabold">z</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
{openModal && (
|
||||
<CreateOrEditOutOfOfficeEntryModal
|
||||
openModal={openModal}
|
||||
closeModal={() => {
|
||||
setOpenModal(false);
|
||||
setCurrentlyEditingOutOfOfficeEntry(null);
|
||||
}}
|
||||
currentlyEditingOutOfOfficeEntry={currentlyEditingOutOfOfficeEntry}
|
||||
/>
|
||||
) : (
|
||||
<div>
|
||||
<DataTable
|
||||
hideHeader={selectedTab === OutOfOfficeTab.MINE}
|
||||
table={table}
|
||||
tableContainerRef={tableContainerRef}
|
||||
isPending={isPending}
|
||||
onScroll={(e) => fetchMoreOnBottomReached(e.target as HTMLDivElement)}>
|
||||
<DataTableToolbar.Root>
|
||||
<DataTableToolbar.SearchBar table={table} onSearch={(value) => setSearchTerm(value)} />
|
||||
</DataTableToolbar.Root>
|
||||
</DataTable>
|
||||
{openModal && (
|
||||
<CreateOrEditOutOfOfficeEntryModal
|
||||
openModal={openModal}
|
||||
closeModal={() => {
|
||||
setOpenModal(false);
|
||||
setCurrentlyEditingOutOfOfficeEntry(null);
|
||||
}}
|
||||
currentlyEditingOutOfOfficeEntry={currentlyEditingOutOfOfficeEntry}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
}
|
||||
@@ -16,7 +16,14 @@ type GetOptions = {
|
||||
|
||||
export const outOfOfficeEntriesList = async ({ ctx, input }: GetOptions) => {
|
||||
const t = await getTranslation(ctx.user.locale, "common");
|
||||
const { cursor, limit, fetchTeamMembersEntries, searchTerm } = input;
|
||||
const {
|
||||
cursor,
|
||||
limit,
|
||||
fetchTeamMembersEntries,
|
||||
searchTerm,
|
||||
endDateFilterStartRange,
|
||||
endDateFilterEndRange,
|
||||
} = input;
|
||||
let fetchOOOEntriesForIds = [ctx.user.id];
|
||||
let reportingUserIds = [0];
|
||||
|
||||
@@ -76,7 +83,8 @@ export const outOfOfficeEntriesList = async ({ ctx, input }: GetOptions) => {
|
||||
in: fetchOOOEntriesForIds,
|
||||
},
|
||||
end: {
|
||||
gte: new Date().toISOString(),
|
||||
gte: endDateFilterStartRange ?? new Date().toISOString(),
|
||||
lte: endDateFilterEndRange,
|
||||
},
|
||||
...(searchTerm
|
||||
? {
|
||||
|
||||
@@ -5,6 +5,8 @@ export const ZOutOfOfficeEntriesListSchema = z.object({
|
||||
cursor: z.number().nullish(),
|
||||
fetchTeamMembersEntries: z.boolean().optional().default(false),
|
||||
searchTerm: z.string().optional(),
|
||||
endDateFilterStartRange: z.string().optional(),
|
||||
endDateFilterEndRange: z.string().optional(),
|
||||
});
|
||||
|
||||
export type TOutOfOfficeEntriesListSchema = z.infer<typeof ZOutOfOfficeEntriesListSchema>;
|
||||
Reference in new issue
Block a user