File tree Expand file tree Collapse file tree 3 files changed +24
-3
lines changed Expand file tree Collapse file tree 3 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -60,4 +60,13 @@ public function getIcon(): ?string
60
60
self ::complete => 'heroicon-m-check-circle ' ,
61
61
};
62
62
}
63
+
64
+ public static function parse (ScheduleStatusEnum |string |null $ value ): ?self
65
+ {
66
+ if ($ value instanceof self) {
67
+ return $ value ;
68
+ }
69
+
70
+ return self ::tryFrom ($ value );
71
+ }
63
72
}
Original file line number Diff line number Diff line change @@ -28,16 +28,21 @@ public static function form(Form $form): Form
28
28
->required ()
29
29
->options (ScheduleStatusEnum::class)
30
30
->default (ScheduleStatusEnum::upcoming)
31
+ ->afterStateUpdated (function (Forms \Set $ set , int |ScheduleStatusEnum $ state ): void {
32
+ if (ScheduleStatusEnum::parse ($ state ) !== ScheduleStatusEnum::complete) {
33
+ $ set ('completed_at ' , null );
34
+ }
35
+ })
31
36
->live (),
32
37
Forms \Components \MarkdownEditor::make ('message ' )
33
38
->columnSpanFull (),
34
- ])->columnspan (3 ),
39
+ ])->columnSpan (3 ),
35
40
Forms \Components \Section::make ()->schema ([
36
41
Forms \Components \DateTimePicker::make ('scheduled_at ' )
37
42
->required (),
38
43
Forms \Components \DateTimePicker::make ('completed_at ' )
39
- ->visible (fn (Forms \Get $ get ): bool => $ get ('status ' ) === ScheduleStatusEnum::complete)
40
- ->markAsRequired (fn (Forms \Get $ get ): bool => $ get ('status ' ) === ScheduleStatusEnum::complete),
44
+ ->visible (fn (Forms \Get $ get ): bool => ScheduleStatusEnum:: parse ( $ get ('status ' ) ) === ScheduleStatusEnum::complete)
45
+ ->required (fn (Forms \Get $ get ): bool => ScheduleStatusEnum:: parse ( $ get ('status ' )) === ScheduleStatusEnum::complete)
41
46
])->columnSpan (1 ),
42
47
])->columns (4 );
43
48
}
Original file line number Diff line number Diff line change @@ -16,4 +16,11 @@ protected function getHeaderActions(): array
16
16
Actions \DeleteAction::make (),
17
17
];
18
18
}
19
+
20
+ protected function mutateFormDataBeforeSave (array $ data ): array
21
+ {
22
+ $ data ['completed_at ' ] = $ data ['completed_at ' ] ?? null ;
23
+
24
+ return $ data ;
25
+ }
19
26
}
You can’t perform that action at this time.
0 commit comments