Skip to content

Commit

Permalink
Oprava odstranění posledního člena (#934)
Browse files Browse the repository at this point in the history
* remove last member fix

* dump removal

* cs fix

* cs fix
  • Loading branch information
jan-stanek committed Apr 5, 2023
1 parent 9015427 commit 5d3531a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/Model/User/Commands/Handlers/UpdateGroupMembersHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,18 @@ public function __invoke(UpdateGroupMembers $command): void
$this->userGroupRoleRepository->save($userGroupRole);
}
}

if (empty($command->getPersons())) {
if ($command->getType() === 'patrol') {
foreach ($patrol->getUsersRoles() as $usersRole) {
$this->userGroupRoleRepository->remove($usersRole);
}
} elseif ($command->getType() === 'troop') {
foreach ($troop->getUsersRoles() as $usersRole) {
$this->userGroupRoleRepository->remove($usersRole);
}
}
}
});
}
}
5 changes: 5 additions & 0 deletions app/WebModule/Components/TroopApplicationContentControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ protected function createComponentGroupMembersForm(): GroupMembersForm
$p->redirect('this', ['step' => 'members', 'type' => $type, 'patrol_id' => $patrolId]);
};

$form->onRemoveAll[] = function (): void {
$p = $this->getPresenter();
$p->redirect('this');
};

return $form;
}

Expand Down
11 changes: 11 additions & 0 deletions app/WebModule/Forms/GroupMembersForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ class GroupMembersForm extends UI\Control
*/
public array $onError = [];

/**
* Událost při odstranění všech členů.
*
* @var callable[]
*/
public array $onRemoveAll = [];

private string $patrolName = '';

/** @var Collection<int, UserGroupRole> */
Expand Down Expand Up @@ -216,6 +223,10 @@ public function processForm(Form $form, stdClass $values): void

$this->commandBus->handle(new UpdateGroupMembers($this->type, $this->troop->getId(), $this->patrolId, $selectedPersons));

if (empty($selectedPersons)) {
$this->onRemoveAll();
}

$this->onSave();
}

Expand Down

0 comments on commit 5d3531a

Please sign in to comment.