mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-app.git
synced 2025-12-13 11:46:47 +00:00
🛠️ Add delete functionality for services with confirmation modal and extend creator name display limit to 20 characters
This commit is contained in:
@@ -19,7 +19,8 @@ class SelfHostedServiceFactory extends Factory
|
||||
$name = $this->faker->unique()->company();
|
||||
|
||||
return [
|
||||
'created_by' => $this->faker->optional()->numberBetween(1,9),
|
||||
// 'created_by' => $this->faker->optional()->numberBetween(1,9),
|
||||
'created_by' => 750,
|
||||
'name' => $name,
|
||||
'slug' => str($name)->slug(),
|
||||
'intro' => $this->faker->optional()->paragraph(),
|
||||
|
||||
@@ -136,7 +136,7 @@ class extends Component {
|
||||
@if($service->createdBy)
|
||||
<div class="flex items-center gap-2">
|
||||
<flux:avatar size="xs" src="{{ $service->createdBy->profile_photo_url }}" />
|
||||
<span>{{ Str::length($service->createdBy->name) > 10 ? Str::substr($service->createdBy->name, 0, 4) . '...' . Str::substr($service->createdBy->name, -3) : $service->createdBy->name }}</span>
|
||||
<span>{{ Str::length($service->createdBy->name) > 20 ? Str::substr($service->createdBy->name, 0, 4) . '...' . Str::substr($service->createdBy->name, -3) : $service->createdBy->name }}</span>
|
||||
</div>
|
||||
@else
|
||||
<span class="text-gray-500 dark:text-gray-400 italic">{{ __('Anonymous') }}</span>
|
||||
|
||||
@@ -20,6 +20,20 @@ class extends Component {
|
||||
$this->country = request()->route('country', config('app.domain_country'));
|
||||
}
|
||||
|
||||
public function delete(): void
|
||||
{
|
||||
// Only allow deletion if user is the creator
|
||||
if (auth()->id() === $this->service->created_by) {
|
||||
$this->service->delete();
|
||||
|
||||
session()->flash('status', __('Service erfolgreich gelöscht!'));
|
||||
|
||||
redirect()->route('services.index', ['country' => $this->country]);
|
||||
} else {
|
||||
abort(403);
|
||||
}
|
||||
}
|
||||
|
||||
public function with(): array
|
||||
{
|
||||
return [
|
||||
@@ -35,9 +49,16 @@ class extends Component {
|
||||
<flux:heading size="xl">{{ $service->name }}</flux:heading>
|
||||
@auth
|
||||
@if(auth()->id() === $service->created_by)
|
||||
<flux:button :href="route_with_country('services.edit', ['service' => $service])" variant="primary" icon="pencil">
|
||||
{{ __('Bearbeiten') }}
|
||||
</flux:button>
|
||||
<div class="flex gap-2">
|
||||
<flux:button :href="route_with_country('services.edit', ['service' => $service])" variant="primary" icon="pencil">
|
||||
{{ __('Bearbeiten') }}
|
||||
</flux:button>
|
||||
<flux:modal.trigger name="delete-service">
|
||||
<flux:button variant="danger" icon="trash">
|
||||
{{ __('Löschen') }}
|
||||
</flux:button>
|
||||
</flux:modal.trigger>
|
||||
</div>
|
||||
@endif
|
||||
@endauth
|
||||
</div>
|
||||
@@ -151,4 +172,24 @@ class extends Component {
|
||||
</flux:button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Delete Confirmation Modal -->
|
||||
<flux:modal name="delete-service" class="space-y-6">
|
||||
<div>
|
||||
<flux:heading size="lg">{{ __('Service löschen?') }}</flux:heading>
|
||||
<flux:text class="mt-2">
|
||||
{{ __('Möchten Sie den Service wirklich löschen? Diese Aktion kann nicht rückgängig gemacht werden.') }}
|
||||
</flux:text>
|
||||
</div>
|
||||
|
||||
<div class="flex gap-2">
|
||||
<flux:spacer />
|
||||
<flux:modal.close>
|
||||
<flux:button variant="ghost">{{ __('Abbrechen') }}</flux:button>
|
||||
</flux:modal.close>
|
||||
<flux:button wire:click="delete" variant="danger">
|
||||
{{ __('Löschen') }}
|
||||
</flux:button>
|
||||
</div>
|
||||
</flux:modal>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user