import type { RoutineEventBlock } from "@rakazo/contracts"; import { isOneShotRoutineCrons } from "@rakazo/core"; import { useRouter } from "expo-router"; import { useState } from "react"; import { Pressable, Text, View } from "react-native"; import { rpc } from "../lib/api"; import { useI18n } from "../lib/i18n"; import { useMobileTokens } from "../lib/native"; import { routineLineSchedule } from "../lib/routine-line"; import { NativeSymbol } from "./native-symbol"; /** A routine the bot set up from the conversation: one quiet line with Edit and Undo. */ export function RoutineEventLine({ block }: { block: RoutineEventBlock }) { const tokens = useMobileTokens(); const { t } = useI18n(); const router = useRouter(); const [undoing, setUndoing] = useState(false); const [failed, setFailed] = useState(false); const oneShot = isOneShotRoutineCrons(block.crons); const schedule = routineLineSchedule(block); const muted = { color: tokens.mutedForeground, fontSize: 13.5 }; async function undo() { setUndoing(true); setFailed(false); try { await rpc("routines/remove", { routineId: block.routineId }); } catch { setFailed(true); } finally { setUndoing(false); } } return ( {block.name} {schedule ? · {schedule} : null} {block.removed ? ( · {t("Removed")} ) : ( <> {block.event === "routine.updated" ? · {t("Updated")} : null} · router.push({ pathname: "/routine", params: { botId: block.botId, routineId: block.routineId }, }) } > {t("Edit")} · void undo()} > {failed ? t("Try again") : t("Undo")} )} ); }