44
55namespace App \Filament \Resources ;
66
7- use App \Filament \Forms \Components \Subsection ;
87use App \Filament \Resources \AppointmentResource \Pages ;
98use App \Filament \Resources \AppointmentResource \RelationManagers \ServicesRelationManager ;
10- use App \Filament \Tables \Columns \TextColumn ;
9+ use App \Filament \Resources \AppointmentResource \Schemas \AppointmentForm ;
10+ use App \Filament \Resources \AppointmentResource \Schemas \AppointmentInfolist ;
1111use App \Models \Appointment ;
12- use Carbon \CarbonImmutable ;
13- use Filament \Forms \Components \DatePicker ;
14- use Filament \Forms \Components \Grid ;
15- use Filament \Forms \Components \RichEditor ;
16- use Filament \Forms \Components \Section ;
17- use Filament \Forms \Components \Select ;
18- use Filament \Forms \Components \TextInput ;
12+ use App \Tables \Columns \TextColumn ;
1913use Filament \Forms \Form ;
2014use Filament \Infolists \Infolist ;
2115use Filament \Resources \Resource ;
2216use Filament \Tables ;
2317use Filament \Tables \Filters \SelectFilter ;
2418use Filament \Tables \Table ;
25- use Illuminate \Database \Eloquent \Builder ;
2619
2720class AppointmentResource extends Resource
2821{
2922 protected static ?string $ model = Appointment::class;
3023
3124 protected static ?int $ navigationSort = 3 ;
3225
26+ protected static ?string $ navigationIcon = 'heroicon-m-calendar-date-range ' ;
27+
3328 public static function getModelLabel (): string
3429 {
3530 return __ ('appointment.label.singular ' );
@@ -43,120 +38,13 @@ public static function getPluralModelLabel(): string
4338 public static function form (Form $ form ): Form
4439 {
4540 return $ form
46- ->columns (1 )
47- ->schema ([
48- Section::make ()
49- ->schema (static ::getAppointmentFormSchema ()),
50- ]);
41+ ->schema (AppointmentForm::getSchema ());
5142 }
5243
5344 public static function infolist (Infolist $ infolist ): Infolist
5445 {
55- return $ infolist ;
56- }
57-
58- public static function getAppointmentFormSchema (): array
59- {
60- return [
61- Subsection::make ()
62- ->title (__ ('appointment.section.mandatory ' ))
63- ->icon ('heroicon-o-document-text ' )
64- ->columns (3 )
65- ->schema ([
66- Select::make ('beneficiary_id ' )
67- ->label (__ ('field.beneficiary ' ))
68- ->relationship ('beneficiary ' , 'full_name ' , fn (Builder $ query ) => $ query ->onlyRegular ())
69- ->searchable ()
70- ->required ()
71- ->preload (),
72-
73- Grid::make (6 )
74- ->columnSpanFull ()
75- ->schema ([
76- DatePicker::make ('date ' )
77- ->label (__ ('field.date ' ))
78- ->required ()
79- ->columnSpan (2 ),
80-
81- TextInput::make ('start_time ' )
82- ->label (__ ('field.start_time ' ))
83- ->type ('time ' )
84- ->rule ('date_format:H:i ' )
85- ->reactive ()
86- ->required ()
87- ->afterStateUpdated (function ($ old , $ state , callable $ get , callable $ set ) {
88- if (blank ($ state )) {
89- return ;
90- }
91-
92- /** @var CarbonImmutable */
93- $ oldStartTime = rescue (
94- fn () => CarbonImmutable::createFromFormat ('H:i ' , $ old ),
95- report: false
96- );
97-
98- /** @var CarbonImmutable */
99- $ endTime = rescue (
100- fn () => CarbonImmutable::createFromFormat ('H:i ' , $ get ('end_time ' )),
101- report: false
102- );
103-
104- $ offset = $ endTime instanceof CarbonImmutable
105- ? $ endTime ->diffInMinutes ($ oldStartTime )
106- : 60 ;
107-
108- $ set (
109- 'end_time ' ,
110- CarbonImmutable::createFromFormat ('H:i ' , $ state )
111- ->addUnitNoOverflow ('minute ' , $ offset , 'day ' )
112- ->format ('H:i ' )
113- );
114- }),
115-
116- TextInput::make ('end_time ' )
117- ->label (__ ('field.end_time ' ))
118- ->type ('time ' )
119- ->after ('start_time ' )
120- ->required ()
121- ->disabled (fn (callable $ get ) => $ get ('start_time ' ) === null ),
122- ]),
123- ]),
124-
125- Subsection::make ()
126- ->title (__ ('appointment.section.additional ' ))
127- ->icon ('heroicon-o-information-circle ' )
128- ->columns (3 )
129- ->schema ([
130- TextInput::make ('type ' )
131- ->label (__ ('field.type ' ))
132- ->columnSpan (2 )
133- ->nullable ()
134- ->maxLength (100 ),
135-
136- TextInput::make ('location ' )
137- ->label (__ ('field.location ' ))
138- ->columnSpan (2 )
139- ->nullable ()
140- ->maxLength (100 ),
141-
142- TextInput::make ('attendant ' )
143- ->label (__ ('field.attendant ' ))
144- ->columnSpan (2 )
145- ->nullable ()
146- ->maxLength (100 ),
147- ]),
148-
149- Subsection::make ()
150- ->title (__ ('appointment.section.notes ' ))
151- ->icon ('heroicon-o-chat-bubble-bottom-center-text ' )
152- ->schema ([
153- RichEditor::make ('notes ' )
154- ->disableLabel ()
155- ->toolbarButtons (['bold ' , 'italic ' , 'strike ' , 'bulletList ' , 'orderedList ' , 'redo ' , 'undo ' ])
156- ->nullable ()
157- ->maxLength (65535 ),
158- ]),
159- ];
46+ return $ infolist
47+ ->schema (AppointmentInfolist::getSchema ());
16048 }
16149
16250 public static function table (Table $ table ): Table
0 commit comments