Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add leave team button #11757

Merged
merged 9 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions app/Http/Controllers/TeamsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@
namespace App\Http\Controllers;

use App\Models\Team;
use App\Models\TeamMember;
use App\Transformers\UserCompactTransformer;
use Symfony\Component\HttpFoundation\Response;

class TeamsController extends Controller
{
public function __construct()
{
parent::__construct();
$this->middleware('auth', ['only' => ['part']]);
}

public function edit(string $id): Response
{
$team = Team::findOrFail($id);
Expand All @@ -21,6 +28,16 @@ public function edit(string $id): Response
return ext_view('teams.edit', compact('team'));
}

public function part(): Response
{
$member = TeamMember::findOrFail(\Auth::user()->getKey());

$member->delete();
\Session::flash('popup', osu_trans('teams.part.ok'));

return ujs_redirect(route('teams.show', ['team' => $member->team_id]));
}

public function show(string $id): Response
{
$team = Team
Expand Down
1 change: 1 addition & 0 deletions resources/css/bem-index.less
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@
@import "bem/supporter-promo";
@import "bem/supporter-quote";
@import "bem/supporter-status";
@import "bem/team-action-button";
@import "bem/team-info-entries";
@import "bem/team-info-entry";
@import "bem/team-members";
Expand Down
4 changes: 4 additions & 0 deletions resources/css/bem/profile-detail-bar.less
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
--padding: @gutter-v2-desktop;
}

&--team {
justify-content: end;
}

&__level {
margin-left: auto;
display: flex;
Expand Down
31 changes: 31 additions & 0 deletions resources/css/bem/team-action-button.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

.team-action-button {
.reset-input();
.link-plain();
.link-white();
.center-content();
.default-text-shadow();
display: flex;
width: auto;
height: 100%;
padding: 10px 30px;
border-radius: 10000px;
text-align: center;
font-weight: bold;
font-size: @font-size--title-small;
background: var(--bg);

--bg: hsl(var(--hsl-b5));
--bg-hover: hsl(var(--hsl-b6));

&:hover {
background: var(--bg-hover);
}

&--part {
--bg: hsl(var(--hsl-red-3));
--bg-hover: hsl(var(--hsl-red-2));
}
}
7 changes: 6 additions & 1 deletion resources/lang/en/teams.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,14 @@
],
],
],

'part' => [
'ok' => 'Left the team ;_;',
],

'show' => [
'bar' => [
'settings' => 'Settings',
'part' => 'Leave Team',
],

'info' => [
Expand Down
21 changes: 21 additions & 0 deletions resources/views/teams/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
$teamMembers['member'] ??= [];
$teamMembers['leader'] ??= $toJson([$team->members()->make(['user_id' => $team->leader_id])->userOrDeleted()]);
$headerUrl = $team->header()->url();

$currentUser = Auth::user();
$buttons = new Ds\Set();
if ($currentUser !== null && $currentUser->team?->getKey() === $team->getKey() && $currentUser->getKey() !== $team->leader_id) {
$buttons->add('part');
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there more buttons coming 👀

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why yes 👀

@endphp

@extends('master', [
Expand Down Expand Up @@ -69,6 +75,21 @@ class="btn-circle btn-circle--page-toggle"
</div>
</div>
</div>
@if (!$buttons->isEmpty())
<div class="profile-detail-bar profile-detail-bar--team">
@if ($buttons->contains('part'))
<form
action="{{ route('teams.part') }}"
data-turbo-confirm="{{ osu_trans('common.confirmation') }}"
method="POST"
>
<button class="team-action-button team-action-button--part">
{{ osu_trans('teams.show.bar.part') }}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too many idents btw

</button>
</form>
@endif
</div>
@endif
<div class="user-profile-pages user-profile-pages--no-tabs">
<div class="page-extra u-fancy-scrollbar">
<div class="team-summary">
Expand Down
1 change: 1 addition & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@
Route::group(['as' => 'teams.', 'prefix' => 'teams/{team}', 'namespace' => 'Teams'], function () {
Route::resource('members', 'MembersController', ['only' => ['destroy', 'index']]);
});
Route::post('teams/part', 'TeamsController@part')->name('teams.part');
Route::resource('teams', 'TeamsController', ['only' => ['edit', 'show', 'update']]);

Route::post('users/check-username-availability', 'UsersController@checkUsernameAvailability')->name('users.check-username-availability');
Expand Down
Loading