AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
feat(frontend): add timezone to new library agent page (#10874)
Ubbee8cf3edbf46a
diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunAgentModal/components/ScheduleView/ScheduleView.tsx b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunAgentModal/components/ScheduleView/ScheduleView.tsxindex e7c148f7d7..7de4c7ea46 100644--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunAgentModal/components/ScheduleView/ScheduleView.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunAgentModal/components/ScheduleView/ScheduleView.tsx@@ -5,6 +5,7 @@ import { Select } from "@/components/atoms/Select/Select";import { useScheduleView } from "./useScheduleView";import { useCallback, useState } from "react";import { validateSchedule } from "./helpers";+import { TimezoneNotice } from "../TimezoneNotice/TimezoneNotice";interface Props {scheduleName: string;@@ -141,8 +142,9 @@ export function ScheduleView({placeholder="00:00"error={errors.time}/>-- {/** Agent inputs are rendered in the main modal; none here. */}+ <div className="-mt-4">+ <TimezoneNotice />+ </div></div>);}diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunAgentModal/components/TimezoneNotice/TimezoneNotice.tsx b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunAgentModal/components/TimezoneNotice/TimezoneNotice.tsxnew file mode 100644index 0000000000..d5d7c011a6--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/RunAgentModal/components/TimezoneNotice/TimezoneNotice.tsx@@ -0,0 +1,41 @@+import { useGetV1GetUserTimezone } from "@/app/api/__generated__/endpoints/auth/auth";+import { getTimezoneDisplayName } from "@/lib/timezone-utils";+import { InfoIcon } from "@phosphor-icons/react";++export function TimezoneNotice() {+ const { data: userTimezone, isSuccess } = useGetV1GetUserTimezone({+ query: {+ select: (res) => (res.status === 200 ? res.data.timezone : undefined),+ },+ });++ if (!isSuccess) {+ return null;+ }++ if (userTimezone === "not-set") {+ return (+ <div className="mt-1 flex items-center gap-2 rounded-md border border-amber-200 bg-amber-50 p-3">+ <InfoIcon className="h-4 w-4 text-amber-600" />+ <p className="text-sm text-amber-800">+ No timezone set. Schedule will run in UTC.+ <a href="/profile/settings" className="ml-1 underline">+ Set your timezone+ </a>+ </p>+ </div>+ );+ }++ const tzName = getTimezoneDisplayName(userTimezone || "UTC");++ return (+ <div className="mt-1 flex items-center gap-2 rounded-md bg-muted/50 p-3">+ <InfoIcon className="h-4 w-4 text-muted-foreground" />+ <p className="text-sm text-muted-foreground">+ Schedule will run in your timezone:{" "}+ <span className="font-medium">{tzName}</span>+ </p>+ </div>+ );+}diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/ScheduleDetails/ScheduleDetails.tsx b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/ScheduleDetails/ScheduleDetails.tsxindex c9365f2a32..9cd20aa6c2 100644--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/ScheduleDetails/ScheduleDetails.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/AgentRunsView/components/ScheduleDetails/ScheduleDetails.tsx@@ -25,7 +25,7 @@ import { useScheduleDetailHeader } from "../RunDetailHeader/useScheduleDetailHeaimport { DeleteScheduleButton } from "./components/DeleteScheduleButton/DeleteScheduleButton";import { humanizeCronExpression } from "@/lib/cron-expression-utils";import { useGetV1GetUserTimezone } from "@/app/api/__generated__/endpoints/auth/auth";-import { formatInTimezone } from "@/lib/timezone-utils";+import { formatInTimezone, getTimezoneDisplayName } from "@/lib/timezone-utils";import { Skeleton } from "@/components/ui/skeleton";import { AgentInputsReadOnly } from "../AgentInputsReadOnly/AgentInputsReadOnly";import { Button } from "@/components/atoms/Button/Button";@@ -96,10 +96,11 @@ export function ScheduleDetails({<RunDetailHeaderagent={agent}run={undefined}- scheduleRecurrence={humanizeCronExpression(- schedule?.cron || "",- userTzRes,- )}+ scheduleRecurrence={+ schedule+ ? `${humanizeCronExpression(schedule.cron || "", userTzRes)} · ${getTimezoneDisplayName(userTzRes || "UTC")}`+ : undefined+ }/></div>{schedule ? (@@ -161,6 +162,10 @@ export function ScheduleDetails({</Text><p className="text-sm text-zinc-600">{humanizeCronExpression(schedule.cron, userTzRes)}+ {" • "}+ <span className="text-xs text-zinc-600">+ {getTimezoneDisplayName(userTzRes || "UTC")}+ </span></p></div><div className="flex flex-col gap-1.5">@@ -179,7 +184,11 @@ export function ScheduleDetails({minute: "2-digit",hour12: false,},- )}+ )}{" "}+ •{" "}+ <span className="text-xs text-zinc-600">+ {getTimezoneDisplayName(userTzRes || "UTC")}+ </span></p></div></div>diff --git a/autogpt_platform/frontend/src/lib/timezone-utils.ts b/autogpt_platform/frontend/src/lib/timezone-utils.tsindex 917ef5343f..d2b0c55102 100644--- a/autogpt_platform/frontend/src/lib/timezone-utils.ts+++ b/autogpt_platform/frontend/src/lib/timezone-utils.ts@@ -22,7 +22,6 @@ export function formatInTimezone(day: "numeric",hour: "2-digit",minute: "2-digit",- timeZoneName: "short",...options,};@@ -112,3 +111,23 @@ export function getTimezoneDisplayName(timezone: string): string {return timezone;}}++/**+ * Get the GMT offset for a given timezone, e.g. "GMT+9" or "UTC"+ */+export function getTimezoneGmtOffset(timezone: string): string {+ if (timezone === "not-set" || !timezone) return "";+ try {+ const date = new Date();+ const formatted = new Intl.DateTimeFormat("en-US", {+ timeZone: timezone,+ timeZoneName: "short",+ }).format(date);++ // Common outputs look like "1/1/2024, GMT+9" or "1/1/2024, UTC"+ const match = formatted.match(/(GMT[+\-]\d{1,2}|UTC)/i);+ return match ? match[0].toUpperCase() : "";+ } catch {+ return "";+ }+}