Skip to content

Commit 0611064

Browse files
committed
wip
1 parent d89bef2 commit 0611064

File tree

40 files changed

+1501
-490
lines changed

40 files changed

+1501
-490
lines changed

apps/dashboard/jobs/tasks/inbox/provider/gmail-sync.ts

Whitespace-only changes.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { schedules, schemaTask } from "@trigger.dev/sdk/v3";
2+
import { generateCronTag } from "jobs/utils/generate-cron-tag";
3+
import { z } from "zod";
4+
5+
export const initialInboxSetup = schemaTask({
6+
id: "initial-inbox-setup",
7+
schema: z.object({
8+
teamId: z.string().uuid(),
9+
connectionId: z.string().uuid(),
10+
}),
11+
maxDuration: 300,
12+
queue: {
13+
concurrencyLimit: 50,
14+
},
15+
run: async (payload) => {
16+
const { teamId, connectionId } = payload;
17+
18+
// Schedule the bank sync task to run daily at a random time to distribute load
19+
// Use a deduplication key to prevent duplicate schedules for the same team
20+
// Add teamId as externalId to use it in the bankSyncScheduler task
21+
// await schedules.create({
22+
// task: bankSyncScheduler.id,
23+
// cron: generateCronTag(teamId),
24+
// timezone: "UTC",
25+
// externalId: teamId,
26+
// deduplicationKey: `${teamId}-${bankSyncScheduler.id}`,
27+
// });
28+
},
29+
});

apps/dashboard/src/app/[locale]/(app)/(sidebar)/inbox/page.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Inbox } from "@/components/inbox";
2+
import { InboxGetStarted } from "@/components/inbox/inbox-get-started";
23
import { InboxViewSkeleton } from "@/components/inbox/inbox-skeleton";
34
import { InboxView } from "@/components/inbox/inbox-view";
45
import { loadInboxFilterParams } from "@/hooks/use-inbox-filter-params";
@@ -23,16 +24,20 @@ export default async function Page(props: Props) {
2324
const params = loadInboxParams(searchParams);
2425

2526
// Change this to prefetch once this is fixed: https://github.com/trpc/trpc/issues/6632
26-
await queryClient.fetchInfiniteQuery(
27+
const data = await queryClient.fetchInfiniteQuery(
2728
trpc.inbox.get.infiniteQueryOptions({
2829
order: params.order,
29-
filter: {
30-
...filter,
31-
done: params.tab === "done",
32-
},
30+
filter,
3331
}),
3432
);
3533

34+
if (
35+
data.pages[0]?.data.length === 0 &&
36+
!Object.values(filter).some((value) => value !== null)
37+
) {
38+
return <InboxGetStarted />;
39+
}
40+
3641
return (
3742
<Inbox>
3843
<Suspense fallback={<InboxViewSkeleton />}>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { getTeamId } from "@/utils/team";
2+
import { InboxConnector } from "@midday/inbox/connector";
3+
import { NextResponse } from "next/server";
4+
5+
export async function GET(request: Request) {
6+
const { searchParams } = new URL(request.url);
7+
const code = searchParams.get("code");
8+
const state = searchParams.get("state") as "gmail" | "outlook";
9+
const teamId = await getTeamId();
10+
11+
if (!code || !state || !teamId) {
12+
return NextResponse.json(
13+
{ error: "Missing required parameters" },
14+
{ status: 400 },
15+
);
16+
}
17+
18+
try {
19+
const connector = new InboxConnector(state);
20+
const acount = await connector.exchangeCodeForAccount({ code, teamId });
21+
22+
console.log({ acount });
23+
24+
// Trigger initial setup
25+
const eventId = "12wefwef23e23";
26+
27+
return NextResponse.redirect(
28+
new URL(`/inbox?event_id=${eventId}`, request.url),
29+
{ status: 302 },
30+
);
31+
} catch (error) {
32+
console.error(error);
33+
return NextResponse.redirect(
34+
new URL("/inbox?connect=failed", request.url),
35+
{ status: 302 },
36+
);
37+
}
38+
}

apps/dashboard/src/components/file-viewer.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ type Props = {
2020

2121
export function FileViewer({ mimeType, url }: Props) {
2222
if (mimeType === "application/pdf") {
23-
return <DynamicPdfViewer url={url} />;
23+
return (
24+
<DynamicPdfViewer
25+
url={url}
26+
// We need to flush because of the React PDF Document Instance
27+
key={Math.random()}
28+
/>
29+
);
2430
}
2531

2632
if (mimeType?.startsWith("image/")) {

apps/dashboard/src/components/image-viewer.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ export function ImageViewer({ url }: { url: string }) {
2323

2424
return (
2525
<div className="relative flex h-full w-full items-center justify-center bg-primary/10">
26-
{isLoading && <Skeleton className="absolute inset-0 h-full w-full" />}
26+
{isLoading && !isError && (
27+
<Skeleton className="absolute inset-0 h-full w-full" />
28+
)}
29+
2730
{isError && <ErrorImage />}
2831

2932
<img
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"use client";
2+
3+
import { useTRPC } from "@/trpc/client";
4+
import { Icons } from "@midday/ui/icons";
5+
import { SubmitButton } from "@midday/ui/submit-button";
6+
import { useMutation } from "@tanstack/react-query";
7+
import { useRouter } from "next/navigation";
8+
9+
export function ConnectGmail() {
10+
const trpc = useTRPC();
11+
const router = useRouter();
12+
13+
const connectMutation = useMutation(
14+
trpc.inbox.connect.mutationOptions({
15+
onSuccess: (data) => {
16+
if (data) {
17+
router.push(data);
18+
}
19+
},
20+
}),
21+
);
22+
23+
return (
24+
<SubmitButton
25+
className="px-6 py-4 w-full font-medium flex space-x-2 h-[40px]"
26+
variant="outline"
27+
onClick={() => connectMutation.mutate({ provider: "gmail" })}
28+
isSubmitting={connectMutation.isPending}
29+
>
30+
<Icons.Gmail />
31+
<span>Connect your Gmail</span>
32+
</SubmitButton>
33+
);
34+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"use client";
2+
3+
import { Button } from "@midday/ui/button";
4+
import { Icons } from "@midday/ui/icons";
5+
6+
export function ConnectOutlook() {
7+
return (
8+
<Button
9+
className="px-6 py-4 w-full font-medium flex space-x-2 h-[40px]"
10+
variant="outline"
11+
>
12+
<Icons.Outlook />
13+
<span>Connect your Outlook</span>
14+
</Button>
15+
);
16+
}

apps/dashboard/src/components/inbox/inbox-details-skeleton.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Skeleton } from "@midday/ui/skeleton";
55

66
export function InboxDetailsSkeleton() {
77
return (
8-
<div className="h-[calc(100vh-120px)] overflow-hidden flex-col border w-[595px] hidden md:flex shrink-0 -mt-[54px]">
8+
<div className="h-[calc(100vh-120px)] overflow-hidden flex-col border w-[615px] hidden md:flex shrink-0 -mt-[54px]">
99
<div className="flex items-center p-2 h-[52px] w-full" />
1010

1111
<Separator />
@@ -23,7 +23,7 @@ export function InboxDetailsSkeleton() {
2323
</div>
2424
</div>
2525
<Separator />
26-
<div className="relative h-full p-4">
26+
<div className="relative h-full">
2727
<Skeleton className="h-full w-full" />
2828
</div>
2929
</div>

0 commit comments

Comments
 (0)