Skip to content

Commit

Permalink
Better UX for Transport removal (& cascade fix)
Browse files Browse the repository at this point in the history
  • Loading branch information
Korbeil committed Apr 18, 2024
1 parent 0c520e8 commit f99891e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion app/src/Discord/Command/RemoveTransportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Discord\Builders\Components\StringSelect;
use Discord\Builders\MessageBuilder;
use Discord\Discord;
use Discord\Parts\Embed\Embed;
use Discord\Parts\Guild\Emoji;
use Discord\Parts\Interactions\Interaction;
use Discord\Parts\User\User as DiscordUser;
Expand Down Expand Up @@ -62,6 +63,9 @@ public function callback(Discord $discord): void
return;
}

$embed = new Embed($discord);
$embed->setTitle(':wastebasket: Are you sure you want to delete your transport ?');

$validation = ActionRow::new()
->addComponent(Button::new(Button::STYLE_DANGER)->setLabel('Delete')->setListener(function (Interaction $interaction) use ($transport): void {
$transportId = $transport->id;
Expand All @@ -74,7 +78,7 @@ public function callback(Discord $discord): void
$interaction->respondWithMessage(MessageBuilder::new()->setContent(':no_entry: Ignoring removal request.'), true);
}, $discord));

$interaction->respondWithMessage(MessageBuilder::new()->setContent(':wastebasket: Are you sure you want to delete your transport ?')->addComponent($validation), true);
$interaction->respondWithMessage(MessageBuilder::new()->addEmbed($embed)->addComponent($validation), true);
});
}
}
2 changes: 1 addition & 1 deletion app/src/Entity/Transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Transport
public int $id;

/** @var Collection<int, Traveler> */
#[ORM\OneToMany(targetEntity: Traveler::class, mappedBy: 'transport', orphanRemoval: true)]
#[ORM\OneToMany(targetEntity: Traveler::class, mappedBy: 'transport', cascade: ['remove'])]
#[ORM\JoinColumn(nullable: false)]
public Collection $travelers;

Expand Down

0 comments on commit f99891e

Please sign in to comment.