Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 2 additions & 17 deletions apps/web/app/(app)/[emailAccountId]/briefs/Onboarding.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,18 @@
"use client";

import {
Card,
CardContent,
CardHeader,
CardFooter,
CardTitle,
CardDescription,
} from "@/components/ui/card";
import {
SectionHeader,
SectionDescription,
MessageText,
} from "@/components/Typography";
import { MessageText } from "@/components/Typography";
import { ConnectCalendar } from "@/app/(app)/[emailAccountId]/calendars/ConnectCalendar";
import { IconCircle } from "@/app/(app)/[emailAccountId]/onboarding/IconCircle";
import {
User,
Mail,
Lightbulb,
UserIcon,
MailIcon,
LightbulbIcon,
InboxIcon,
} from "lucide-react";
import { UserIcon, MailIcon, LightbulbIcon } from "lucide-react";
import { Button } from "@/components/ui/button";
import {
Item,
ItemActions,
ItemContent,
ItemDescription,
ItemGroup,
Expand Down
37 changes: 14 additions & 23 deletions apps/web/app/(app)/[emailAccountId]/briefs/TimeDurationSetting.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { useCallback, useEffect, useState } from "react";
import { useCallback, useState } from "react";
import { useForm, type FieldErrors } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { useDebounceCallback } from "usehooks-ts";
Expand Down Expand Up @@ -47,14 +47,11 @@ export function TimeDurationSetting({
}) {
const { emailAccountId } = useAccount();

const {
handleSubmit,
setValue: setFormValue,
reset,
} = useForm<UpdateMeetingBriefsMinutesBeforeBody>({
resolver: zodResolver(updateMeetingBriefsMinutesBeforeBody),
defaultValues: { minutesBefore: initialMinutes },
});
const { handleSubmit, setValue: setFormValue } =
useForm<UpdateMeetingBriefsMinutesBeforeBody>({
resolver: zodResolver(updateMeetingBriefsMinutesBeforeBody),
defaultValues: { minutesBefore: initialMinutes },
});

const [value, setValue] = useState(
() => minutesToValueAndUnit(initialMinutes).value,
Expand All @@ -76,7 +73,10 @@ export function TimeDurationSetting({
return;
}

toastSuccess({ description: "Settings saved!" });
toastSuccess({
description: "Settings saved!",
id: "time-duration-saved",
});
onSaved();
},
[executeAsync, onSaved],
Expand All @@ -91,26 +91,18 @@ export function TimeDurationSetting({
);

const updateAndSubmit = useDebounceCallback((nextMinutesBefore: number) => {
setFormValue("minutesBefore", nextMinutesBefore, {
shouldValidate: true,
});
setFormValue("minutesBefore", nextMinutesBefore, { shouldValidate: true });
handleSubmit(onSubmit, onError)();
}, 500);

// Keep local UI in sync if the server value changes (e.g. after revalidation)
useEffect(() => {
if (isExecuting) return;
const parsed = minutesToValueAndUnit(initialMinutes);
setValue(parsed.value);
setUnit(parsed.unit);
reset({ minutesBefore: initialMinutes });
}, [initialMinutes, reset, isExecuting]);

return (
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The UI can show stale values after initialMinutes changes because the useEffect that synced value/unit (and called reset) was removed. Consider re-adding that sync so the input/select reflect server updates; if this is intentional, consider documenting the rationale.

🚀 Want me to fix this? Reply ex: "fix it for me".

<form
className="flex items-center gap-1"
onSubmit={handleSubmit(onSubmit, onError)}
>
<div className="flex w-5 items-center justify-center">
{isExecuting && <LoadingMiniSpinner />}
</div>
<Input
type="number"
min={1}
Expand Down Expand Up @@ -138,7 +130,6 @@ export function TimeDurationSetting({
<SelectItem value="hours">hours</SelectItem>
</SelectContent>
</Select>
{isExecuting && <LoadingMiniSpinner />}
</form>
);
}
7 changes: 6 additions & 1 deletion apps/web/components/Toast.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { Toaster as SonnerToaster, toast } from "sonner";

export function toastSuccess(options: { title?: string; description: string }) {
export function toastSuccess(options: {
title?: string;
description: string;
id?: string;
}) {
return toast.success(options.title || "Success", {
description: options.description,
id: options.id,
});
}

Expand Down
Loading