@@ -4,14 +4,21 @@ import type {
44 ScheduledTask ,
55 ScheduledTaskUpsertInput ,
66} from "@t3tools/contracts" ;
7- import { resolveEnvironmentMachineKind } from "@t3tools/contracts" ;
7+ import {
8+ MAX_WEBHOOK_DELIVERY_AGE_MINUTES ,
9+ resolveEnvironmentMachineKind ,
10+ } from "@t3tools/contracts" ;
811import type { MenuAction } from "@react-native-menu/menu" ;
912import { DateTimePicker } from "@expo/ui/community/datetime-picker" ;
1013import {
1114 isAtomCommandInterrupted ,
1215 squashAtomCommandFailure ,
1316 type AtomCommandResult ,
1417} from "@t3tools/client-runtime/state/runtime" ;
18+ import {
19+ DEFAULT_WEBHOOK_PROMPT ,
20+ parseMaxDeliveryAge ,
21+ } from "@t3tools/client-runtime/scheduled-task-webhook" ;
1522import {
1623 useCallback ,
1724 useEffect ,
@@ -59,7 +66,6 @@ import { SettingsSection } from "./components/SettingsSection";
5966import { useSettingsEnvironmentFilter , type SettingsTarget } from "./settings-environment-filter" ;
6067import {
6168 editDraft ,
62- DEFAULT_WEBHOOK_PROMPT ,
6369 scheduledTaskDefaultModel ,
6470 scheduleFromDraft ,
6571 type ScheduledTaskDraft as Draft ,
@@ -132,7 +138,7 @@ function FormField(props: {
132138 readonly label : string ;
133139 readonly value : string ;
134140 readonly onChange : ( value : string ) => void ;
135- readonly keyboardType ?: "decimal-pad" ;
141+ readonly keyboardType ?: "decimal-pad" | "number-pad" ;
136142 readonly disabled ?: boolean ;
137143 readonly placeholder ?: string ;
138144 readonly borderTop ?: boolean ;
@@ -611,6 +617,16 @@ function TaskForm({
611617 ? { ...draft . schedule , signature : liveTask . schedule . signature }
612618 : draft . schedule ,
613619 ) ;
620+ if (
621+ draft . schedule . mode === "webhook" &&
622+ parseMaxDeliveryAge ( draft . schedule . maxDeliveryAgeMinutes ) === undefined
623+ ) {
624+ Alert . alert (
625+ "Invalid age limit" ,
626+ `Enter whole minutes from 1 to ${ MAX_WEBHOOK_DELIVERY_AGE_MINUTES } , or leave it blank.` ,
627+ ) ;
628+ return ;
629+ }
614630 if (
615631 ! draft . title . trim ( ) ||
616632 ! draft . prompt . trim ( ) ||
@@ -823,7 +839,7 @@ function TaskForm({
823839 options = { [
824840 { value : "fixed_time" , label : "At a time" } ,
825841 { value : "interval" , label : "Interval" } ,
826- { value : "webhook" , label : "Webhook " } ,
842+ { value : "webhook" , label : "On webhook " } ,
827843 ] }
828844 selected = { draft . schedule . mode }
829845 onSelect = { ( mode ) => {
@@ -910,13 +926,31 @@ function TaskForm({
910926 />
911927 </ >
912928 ) : draft . schedule . mode === "webhook" ? (
913- < WebhookScheduleDetails
914- environmentId = { environmentId }
915- task = {
916- tasks . data ?. tasks . find ( ( task ) => task . id === draft . task ?. id ) ?? draft . task ?? null
917- }
918- signatureConfigured = { draft . schedule . signature !== null }
919- />
929+ < >
930+ < WebhookScheduleDetails
931+ environmentId = { environmentId }
932+ // The live row, so a rotated URL shows up without reopening the form.
933+ // Once the list has loaded, a missing task is gone; don't keep showing its URL.
934+ task = {
935+ tasks . data
936+ ? ( tasks . data . tasks . find ( ( task ) => task . id === draft . task ?. id ) ?? null )
937+ : draft . task
938+ }
939+ signatureConfigured = { draft . schedule . signature !== null }
940+ disabled = { saving || environmentUnavailable }
941+ />
942+ < FormField
943+ label = "Skip requests older than (minutes)"
944+ value = { draft . schedule . maxDeliveryAgeMinutes }
945+ placeholder = "Run every request"
946+ keyboardType = "number-pad"
947+ disabled = { saving }
948+ borderTop
949+ onChange = { ( maxDeliveryAgeMinutes ) =>
950+ setDraft ( { ...draft , schedule : { ...draft . schedule , maxDeliveryAgeMinutes } } )
951+ }
952+ />
953+ </ >
920954 ) : (
921955 < >
922956 < FormField
@@ -976,11 +1010,14 @@ function WebhookScheduleDetails({
9761010 environmentId,
9771011 task,
9781012 signatureConfigured,
1013+ disabled,
9791014} : {
9801015 readonly environmentId : EnvironmentId ;
9811016 readonly task : ScheduledTask | null ;
9821017 readonly signatureConfigured : boolean ;
1018+ readonly disabled : boolean ;
9831019} ) {
1020+ const [ rotating , setRotating ] = useState ( false ) ;
9841021 const rotate = useAtomCommand ( serverEnvironment . rotateScheduledTaskWebhookToken , {
9851022 label : "scheduled task rotate webhook token" ,
9861023 reportFailure : false ,
@@ -1023,27 +1060,34 @@ function WebhookScheduleDetails({
10231060 ) : null }
10241061 < Pressable
10251062 accessibilityRole = "button"
1063+ accessibilityState = { { disabled : disabled || rotating } }
1064+ disabled = { disabled || rotating }
10261065 onPress = { ( ) =>
10271066 Alert . alert ( "Rotate URL?" , "The current URL stops working immediately." , [
10281067 { text : "Cancel" , style : "cancel" } ,
10291068 {
10301069 text : "Rotate" ,
10311070 style : "destructive" ,
1032- onPress : ( ) =>
1071+ onPress : ( ) => {
1072+ setRotating ( true ) ;
10331073 void rotate ( { environmentId, input : { id : task . id } } ) . then ( ( result ) => {
1074+ setRotating ( false ) ;
10341075 if ( result . _tag === "Failure" && ! isAtomCommandInterrupted ( result ) ) {
10351076 Alert . alert (
10361077 "Could not rotate URL" ,
10371078 String ( squashAtomCommandFailure ( result ) ) ,
10381079 ) ;
10391080 }
1040- } ) ,
1081+ } ) ;
1082+ } ,
10411083 } ,
10421084 ] )
10431085 }
1044- className = "min-h-11 justify-center active:opacity-70"
1086+ className = "min-h-11 justify-center active:opacity-70 disabled:opacity-50 "
10451087 >
1046- < Text className = "text-base text-danger-foreground" > Rotate URL</ Text >
1088+ < Text className = "text-base text-danger-foreground" >
1089+ { rotating ? "Rotating…" : "Rotate URL" }
1090+ </ Text >
10471091 </ Pressable >
10481092 </ >
10491093 ) }
0 commit comments