Action::make('search_by_code')
->label(__('search_by_code'))
->modalwidth(Width::Medium)
->modalCancelAction(false)
->schema([
TextInput::make('referral_code')
->label('referral_code')
->maxLength(11)
->mask('*****-*****')
->placeholder('*****-*****')
->default('12345-ABCDEF') // Todo : Remove
->columnSpanFull()
->required()
->regex('/^(?:\d{5}-[A-Z]{5}|[A-Z]{5}-\d{5})$/i')
->afterStateUpdated(fn (Set $set) => $set('search_view', null)),
Hidden::make('search_view')->dehydrated(false),
View::make('filament.user.resources.companies.actions.referral_code_responce')
->viewData(fn (Get $get) => [
'result' => $get('search_view'),
])
->hidden(fn (Get $get) => blank($get('search_view'))),
])
->action(function (array $data, Action $action) {
$code = strtoupper($data['referral_code']);
$company = Company::query()->where('referral_code', $code)->first();
// This does not work
// $set('search_view', $company
// ? ['status' => 'found', 'company' => ['id' => $company->id, 'name' => $company->name]]
// : ['status' => 'not_found']
// );
$action->halt();
})
Action::make('search_by_code')
->label(__('search_by_code'))
->modalwidth(Width::Medium)
->modalCancelAction(false)
->schema([
TextInput::make('referral_code')
->label('referral_code')
->maxLength(11)
->mask('*****-*****')
->placeholder('*****-*****')
->default('12345-ABCDEF') // Todo : Remove
->columnSpanFull()
->required()
->regex('/^(?:\d{5}-[A-Z]{5}|[A-Z]{5}-\d{5})$/i')
->afterStateUpdated(fn (Set $set) => $set('search_view', null)),
Hidden::make('search_view')->dehydrated(false),
View::make('filament.user.resources.companies.actions.referral_code_responce')
->viewData(fn (Get $get) => [
'result' => $get('search_view'),
])
->hidden(fn (Get $get) => blank($get('search_view'))),
])
->action(function (array $data, Action $action) {
$code = strtoupper($data['referral_code']);
$company = Company::query()->where('referral_code', $code)->first();
// This does not work
// $set('search_view', $company
// ? ['status' => 'found', 'company' => ['id' => $company->id, 'name' => $company->name]]
// : ['status' => 'not_found']
// );
$action->halt();
})