Skip to content

Commit

Permalink
feat: add flash messages to cancel membership and update wording
Browse files Browse the repository at this point in the history
Enhanced the `cancelMembership` action to show flash messages to provide feedback. Also changed the wording to be more descriptive as to what action was actually performed and to be in Dutch like the rest of the UI.
  • Loading branch information
LukaBerkers committed Nov 17, 2024
1 parent 5ec8f92 commit c830760
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/Controller/Admin/MemberCrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
use EasyCorp\Bundle\EasyAdminBundle\Dto\SearchDto;
use EasyCorp\Bundle\EasyAdminBundle\Orm\EntityRepository;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use EasyCorp\Bundle\EasyAdminBundle\Field\{ Field, IdField, BooleanField, FormField, DateField, DateTimeField, CollectionField, ChoiceField, TextField, EmailField, AssociationField, MoneyField };
use EasyCorp\Bundle\EasyAdminBundle\Config\{ Crud, Filters, Actions, Action };
use EasyCorp\Bundle\EasyAdminBundle\Filter\{ EntityFilter };
Expand Down Expand Up @@ -71,28 +72,39 @@ public function configureActions(Actions $actions): Actions {
$actions->add(Crud::PAGE_INDEX, $action);
$contributionEnabled = $this->getParameter('app.contributionEnabled');
if ($contributionEnabled) {
$actionCancelMollie = Action::new('cancel', 'Lidmaatschap stoppen', 'fa fa-dollar-sign')
->linkToCrudAction('cancelMembership')
->setCssClass('btn btn-secondary');
$actionCancelMollie =
Action::new('cancel', 'Contributiebetaling stopzetten', 'fa fa-dollar-sign')
->linkToCrudAction('cancelMembership')
->setCssClass('btn btn-secondary');
$actions->add(Crud::PAGE_EDIT, $actionCancelMollie);
}
return $actions;
}

public function cancelMembership(AdminContext $adminContext, MollieApiClient $mollieApiClient): Response
public function cancelMembership(AdminContext $adminContext,
MollieApiClient $mollieApiClient,
AdminUrlGenerator $adminUrlGenerator): Response
{
$member = $adminContext->getEntity()->getInstance();
$redirectUrl = $adminUrlGenerator
->setController(self::class)
->setAction(Crud::PAGE_EDIT)
->setEntityId($member->getId())
->generateUrl();

if ($member->getMollieSubscriptionId() === null)
{
return new Response('Membership already cancelled');
$this->addFlash('warning', 'Contributiebetaling is al gestopt.');
return $this->redirect($redirectUrl);
}
$customer = $mollieApiClient->customers->get($member->getMollieCustomerId());
$subscription = $mollieApiClient->subscriptions->getFor($customer, $member->getMollieSubscriptionId());
$subscription->cancel();
$member->setMollieSubscriptionId(null);
$em = $this->getDoctrine()->getManager();
$em->flush();
return new Response('Membership cancelled succesfully');
$this->addFlash('success', 'Contributiebetaling succesvol stopgezet.');
return $this->redirect($redirectUrl);
}

public function export(AdminContext $adminContext): BinaryFileResponse
Expand Down

0 comments on commit c830760

Please sign in to comment.