|
@@ -8,6 +8,7 @@ use App\Models\Locale\City;
|
8
|
8
|
use App\Models\Locale\Country;
|
9
|
9
|
use App\Models\Locale\State;
|
10
|
10
|
use App\Models\Setting\CompanyProfile as CompanyProfileModel;
|
|
11
|
+use App\Utilities\Localization\Timezone;
|
11
|
12
|
use Filament\Actions\Action;
|
12
|
13
|
use Filament\Actions\ActionGroup;
|
13
|
14
|
use Filament\Forms\Components\Component;
|
|
@@ -90,12 +91,50 @@ class CompanyProfile extends Page
|
90
|
91
|
$data = $this->form->getState();
|
91
|
92
|
|
92
|
93
|
$this->handleRecordUpdate($this->record, $data);
|
93
|
|
-
|
94
|
94
|
} catch (Halt $exception) {
|
95
|
95
|
return;
|
96
|
96
|
}
|
97
|
97
|
|
|
98
|
+ $countryChanged = $this->record->wasChanged('country');
|
|
99
|
+ $stateChanged = $this->record->wasChanged('state_id');
|
|
100
|
+
|
98
|
101
|
$this->getSavedNotification()->send();
|
|
102
|
+
|
|
103
|
+ if ($countryChanged || $stateChanged) {
|
|
104
|
+ if ($countryChanged) {
|
|
105
|
+ $this->updateTimezone($this->record->country);
|
|
106
|
+ }
|
|
107
|
+
|
|
108
|
+ $this->getTimezoneChangeNotification()->send();
|
|
109
|
+ }
|
|
110
|
+ }
|
|
111
|
+
|
|
112
|
+ protected function updateTimezone(string $countryCode): void
|
|
113
|
+ {
|
|
114
|
+ $model = \App\Models\Setting\Localization::firstOrFail();
|
|
115
|
+
|
|
116
|
+ $timezones = Timezone::getTimezonesForCountry($countryCode);
|
|
117
|
+
|
|
118
|
+ if (! empty($timezones)) {
|
|
119
|
+ $model->update([
|
|
120
|
+ 'timezone' => $timezones[0],
|
|
121
|
+ ]);
|
|
122
|
+ }
|
|
123
|
+ }
|
|
124
|
+
|
|
125
|
+ protected function getTimezoneChangeNotification(): Notification
|
|
126
|
+ {
|
|
127
|
+ return Notification::make()
|
|
128
|
+ ->warning()
|
|
129
|
+ ->title('Timezone Update Required')
|
|
130
|
+ ->body('You have changed your country or state. Please update your timezone to ensure accurate date and time information.')
|
|
131
|
+ ->actions([
|
|
132
|
+ \Filament\Notifications\Actions\Action::make('updateTimezone')
|
|
133
|
+ ->label('Update Timezone')
|
|
134
|
+ ->url(Localization::getUrl()),
|
|
135
|
+ ])
|
|
136
|
+ ->persistent()
|
|
137
|
+ ->send();
|
99
|
138
|
}
|
100
|
139
|
|
101
|
140
|
protected function getSavedNotification(): Notification
|
|
@@ -176,6 +215,7 @@ class CompanyProfile extends Page
|
176
|
215
|
->searchable()
|
177
|
216
|
->live()
|
178
|
217
|
->options(static fn (Get $get) => State::getStateOptions($get('country')))
|
|
218
|
+ ->afterStateUpdated(static fn (Set $set) => $set('city_id', null))
|
179
|
219
|
->nullable(),
|
180
|
220
|
TextInput::make('address')
|
181
|
221
|
->localizeLabel('Street Address')
|