Vollstaendige Gastdaten direkt im Zuordnungsdialog erfassen
Deploy FeWo mit PipelineManager / deploy (push) Successful in 2m48s
Deploy FeWo mit PipelineManager / deploy (push) Successful in 2m48s
This commit is contained in:
1 parent
13f1b5856c
commit
78aafd7c28
6 files changed
+105
-28
No files matched your search
@@ -13,7 +13,7 @@
|
||||
|
||||
class AssignOccupationGuest
|
||||
{
|
||||
/** @param array{first_name?: string, last_name?: ?string, email?: ?string, phone?: ?string} $details */
|
||||
/** @param array{first_name?: string, last_name?: ?string, email?: ?string, phone?: ?string, street?: ?string, postal_code?: ?string, city?: ?string, country?: ?string, notes?: ?string, tags?: ?array} $details */
|
||||
public function handle(Booking|BlockedPeriod $occupation, ?int $guestId, array $details = []): Guest
|
||||
{
|
||||
Gate::authorize('update', $occupation);
|
||||
@@ -33,8 +33,15 @@ public function handle(Booking|BlockedPeriod $occupation, ?int $guestId, array $
|
||||
'last_name' => ['nullable', 'string', 'max:255'],
|
||||
'email' => ['nullable', 'email', 'max:255'],
|
||||
'phone' => ['nullable', 'string', 'max:50'],
|
||||
'street' => ['nullable', 'string', 'max:255'],
|
||||
'postal_code' => ['nullable', 'string', 'max:20'],
|
||||
'city' => ['nullable', 'string', 'max:255'],
|
||||
'country' => ['nullable', 'string', 'size:2', 'regex:/^[A-Z]{2}$/'],
|
||||
'notes' => ['nullable', 'string'],
|
||||
'tags' => ['nullable', 'array'],
|
||||
'tags.*' => ['string', 'max:255'],
|
||||
])->validate();
|
||||
$guest = new Guest([...$data, 'last_name' => $data['last_name'] ?? '', 'email' => filled($data['email'] ?? null) ? mb_strtolower(trim($data['email'])) : null]);
|
||||
$guest = new Guest([...$data, 'last_name' => $data['last_name'] ?? '', 'email' => filled($data['email'] ?? null) ? mb_strtolower(trim($data['email'])) : null, 'country' => $data['country'] ?? 'DE']);
|
||||
$guest->forceFill(['tenant_id' => $record->tenant_id])->save();
|
||||
}
|
||||
$record->forceFill(['guest_id' => $guest->id])->save();
|
||||
|
||||
@@ -4,13 +4,14 @@
|
||||
|
||||
use App\Actions\AssignOccupationGuest;
|
||||
use App\Enums\OccupationKind;
|
||||
use App\Filament\Resources\Guests\Schemas\GuestForm;
|
||||
use App\Models\BlockedPeriod;
|
||||
use App\Models\Booking;
|
||||
use App\Models\Guest;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Components\Utilities\Get;
|
||||
|
||||
class AssignGuestAction
|
||||
@@ -18,12 +19,13 @@ class AssignGuestAction
|
||||
public static function make(): Action
|
||||
{
|
||||
return Action::make('assignGuest')->label('Gast zuordnen')
|
||||
->modalWidth('3xl')
|
||||
->visible(fn (Booking|BlockedPeriod $record): bool => auth()->user()?->can('update', $record)
|
||||
&& ($record instanceof Booking || (! $record->trashed() && ! $record->is_representation && $record->occupationKind() === OccupationKind::Reservation)))
|
||||
->authorize(fn (Booking|BlockedPeriod $record): bool => auth()->user()?->can('update', $record) ?? false)
|
||||
->modalDescription('Einen vorhandenen Gast persönlich auswählen oder einen neuen Gast anlegen. Ein Namensfragment ist kein Identitätsnachweis. Die Zuordnung versendet keine Nachricht und ändert keine Belegungszeiträume.')
|
||||
->fillForm(fn (Booking|BlockedPeriod $record): array => [
|
||||
'mode' => 'existing', 'guest_id' => $record->guest_id,
|
||||
'mode' => 'existing', 'guest_id' => $record->guest_id, 'country' => 'DE',
|
||||
'first_name' => $record instanceof BlockedPeriod ? ($record->ical_interpretation['fields']['guest_first_name'] ?? '') : '',
|
||||
])
|
||||
->schema([
|
||||
@@ -34,11 +36,10 @@ public static function make(): Action
|
||||
->orderBy('last_name')->orderBy('id')->limit(50)->get()->mapWithKeys(fn (Guest $guest): array => [$guest->id => $guest->full_name.($guest->email ? ' · '.$guest->email : ' · E-Mail unbekannt')])->all())
|
||||
->getOptionLabelUsing(fn ($value): ?string => Guest::find($value)?->full_name)
|
||||
->visible(fn (Get $get): bool => $get('mode') === 'existing')->required(fn (Get $get): bool => $get('mode') === 'existing'),
|
||||
TextInput::make('first_name')->label('Vorname / verfügbarer Namensbestandteil')->maxLength(255)
|
||||
->visible(fn (Get $get): bool => $get('mode') === 'new')->required(fn (Get $get): bool => $get('mode') === 'new'),
|
||||
TextInput::make('last_name')->label('Nachname, sofern bekannt')->maxLength(255)->visible(fn (Get $get): bool => $get('mode') === 'new'),
|
||||
TextInput::make('email')->label('E-Mail, sofern bekannt')->email()->maxLength(255)->visible(fn (Get $get): bool => $get('mode') === 'new'),
|
||||
TextInput::make('phone')->label('Telefon, sofern bekannt')->maxLength(50)->visible(fn (Get $get): bool => $get('mode') === 'new'),
|
||||
Section::make('Kontakt & Adresse')->columns(2)->visible(fn (Get $get): bool => $get('mode') === 'new')
|
||||
->schema(GuestForm::contactFields()),
|
||||
Section::make('Notizen & Markierungen')->visible(fn (Get $get): bool => $get('mode') === 'new')
|
||||
->schema(GuestForm::personalFields()),
|
||||
])
|
||||
->action(function (Booking|BlockedPeriod $record, array $data, AssignOccupationGuest $assign): void {
|
||||
$assign->handle($record, $data['mode'] === 'existing' ? (int) $data['guest_id'] : null, $data);
|
||||
|
||||
@@ -21,26 +21,11 @@ public static function configure(Schema $schema): Schema
|
||||
Section::make('Kontakt')
|
||||
->columnSpan(2)
|
||||
->columns(2)
|
||||
->schema([
|
||||
TextInput::make('first_name')->label('Vorname')->required()->maxLength(255),
|
||||
TextInput::make('last_name')->label('Nachname')->maxLength(255)->dehydrateStateUsing(fn (?string $state): string => $state ?? ''),
|
||||
TextInput::make('email')->label('E-Mail')->email()->maxLength(255)->dehydrateStateUsing(fn (?string $state): ?string => filled($state) ? $state : null)->helperText('Bei Portalgästen gegebenenfalls noch unbekannt. Keine Ersatzadresse eintragen.'),
|
||||
TextInput::make('phone')->label('Telefon')->tel()->maxLength(50),
|
||||
TextInput::make('street')->label('Straße')->maxLength(255),
|
||||
TextInput::make('postal_code')->label('PLZ')->maxLength(20),
|
||||
TextInput::make('city')->label('Ort')->maxLength(255),
|
||||
Select::make('country')
|
||||
->label('Land')
|
||||
->options(['DE' => 'Deutschland', 'AT' => 'Österreich', 'CH' => 'Schweiz', 'NL' => 'Niederlande', 'DK' => 'Dänemark', 'PL' => 'Polen'])
|
||||
->default('DE')
|
||||
->required(),
|
||||
]),
|
||||
->schema(static::contactFields()),
|
||||
Section::make('Verwaltung')
|
||||
->columnSpan(1)
|
||||
->schema([
|
||||
TagsInput::make('tags')
|
||||
->label('Markierungen')
|
||||
->suggestions(['Stammgast', 'Familie', 'Empfehlung', 'Nicht wieder vermieten']),
|
||||
...static::personalFields(),
|
||||
TextEntry::make('marketing_consent_at')
|
||||
->label('Einwilligung Angebote per E-Mail')
|
||||
->state(fn (?Guest $record): string => $record?->marketing_consent_at ? 'bestätigt am '.$record->marketing_consent_at->format('d.m.Y') : 'keine'),
|
||||
@@ -48,8 +33,33 @@ public static function configure(Schema $schema): Schema
|
||||
->label('Anonymisiert')
|
||||
->dateTime('d.m.Y')
|
||||
->visible(fn (?Guest $record): bool => $record?->anonymized_at !== null),
|
||||
Textarea::make('notes')->label('Notizen')->rows(5),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
/** @return array<TextInput|Select> */
|
||||
public static function contactFields(): array
|
||||
{
|
||||
return [
|
||||
TextInput::make('first_name')->label('Vorname')->required()->maxLength(255),
|
||||
TextInput::make('last_name')->label('Nachname')->maxLength(255)->dehydrateStateUsing(fn (?string $state): string => $state ?? ''),
|
||||
TextInput::make('email')->label('E-Mail')->email()->maxLength(255)->dehydrateStateUsing(fn (?string $state): ?string => filled($state) ? $state : null)->helperText('Bei Portalgästen gegebenenfalls noch unbekannt. Keine Ersatzadresse eintragen.'),
|
||||
TextInput::make('phone')->label('Telefon')->tel()->maxLength(50),
|
||||
TextInput::make('street')->label('Straße')->maxLength(255),
|
||||
TextInput::make('postal_code')->label('PLZ')->maxLength(20),
|
||||
TextInput::make('city')->label('Ort')->maxLength(255),
|
||||
Select::make('country')->label('Land')
|
||||
->options(['DE' => 'Deutschland', 'AT' => 'Österreich', 'CH' => 'Schweiz', 'NL' => 'Niederlande', 'DK' => 'Dänemark', 'PL' => 'Polen'])
|
||||
->default('DE')->required(),
|
||||
];
|
||||
}
|
||||
|
||||
/** @return array<TagsInput|Textarea> */
|
||||
public static function personalFields(): array
|
||||
{
|
||||
return [
|
||||
TagsInput::make('tags')->label('Markierungen')->suggestions(['Stammgast', 'Familie', 'Empfehlung', 'Nicht wieder vermieten']),
|
||||
Textarea::make('notes')->label('Notizen')->rows(5),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user