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) Request #3636 #3649

Merged
merged 4 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 1 addition & 6 deletions app/Http/Controllers/Staff/ApplicationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,7 @@ class ApplicationController extends Controller
*/
public function index(): \Illuminate\Contracts\View\Factory|\Illuminate\View\View
{
return view('Staff.application.index', [
'applications' => Application::withoutGlobalScope(ApprovedScope::class)
->with(['user.group', 'moderated.group', 'imageProofs', 'urlProofs'])
->latest()
->paginate(25),
]);
return view('Staff.application.index');
}

/**
Expand Down
76 changes: 76 additions & 0 deletions app/Http/Livewire/ApplicationSearch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/

namespace App\Http\Livewire;

use App\Models\Application;
use App\Models\Scopes\ApprovedScope;
use App\Traits\LivewireSort;
use Livewire\Attributes\Computed;
use Livewire\Attributes\Url;
use Livewire\Component;
use Livewire\WithPagination;

class ApplicationSearch extends Component
{
use LivewireSort;
use WithPagination;

#TODO: Update URL attributes once Livewire 3 fixes upstream bug. See: https://github.com/livewire/livewire/discussions/7746

#[Url(history: true)]
public string $email = '';

#[Url(history: true)]
public string $status = '';

#[Url(history: true)]
public string $sortField = 'created_at';

#[Url(history: true)]
public string $sortDirection = 'desc';

#[Url(history: true)]
public int $perPage = 25;

#[Computed]
final public function applications(): \Illuminate\Contracts\Pagination\LengthAwarePaginator
{
return Application::withoutGlobalScope(ApprovedScope::class)->with([
'user.group', 'moderated.group', 'imageProofs', 'urlProofs'
])
->when($this->email, fn ($query) => $query->where('email', 'LIKE', '%'.$this->email.'%'))
->when($this->status, fn ($query) => $query->where('status', '=', $this->status))
->orderBy($this->sortField, $this->sortDirection)
->paginate($this->perPage);
}

final public function destroy(int $id): void
{
abort_unless(auth()->user()->group->is_modo, 403);

$application = Application::withoutGlobalScopes()->findOrFail($id);
$application->urlProofs()->delete();
$application->imageProofs()->delete();
$application->delete();

$this->dispatch('success', type: 'success', message: 'Application has successfully been deleted!');
}

final public function render(): \Illuminate\Contracts\View\View|\Illuminate\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\Foundation\Application
{
return view('livewire.application-search', [
'applications' => $this->applications
]);
}
}
10 changes: 10 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,16 @@ parameters:
count: 4
path: app/Http/Controllers/User/WarningController.php

-
message: "#^Method App\\\\Http\\\\Livewire\\\\ApplicationSearch\\:\\:applications\\(\\) return type with generic interface Illuminate\\\\Contracts\\\\Pagination\\\\LengthAwarePaginator does not specify its types\\: TItem$#"
count: 1
path: app/Http/Livewire/ApplicationSearch.php

-
message: "#^Parameter \\#1 \\$boolean of function abort_unless expects bool, int given\\.$#"
count: 1
path: app/Http/Livewire/ApplicationSearch.php

-
message: "#^Property App\\\\Http\\\\Livewire\\\\AttachmentUpload\\:\\:\\$attachment has no type specified\\.$#"
count: 1
Expand Down
92 changes: 1 addition & 91 deletions resources/views/Staff/application/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,95 +22,5 @@
@section('page', 'page__application--index')

@section('main')
<section class="panelV2">
<h2 class="panel__heading">{{ __('staff.applications') }}</h2>
<div class="data-table-wrapper">
<table class="data-table">
<thead>
<tr>
<th>#</th>
<th>{{ __('common.user') }}</th>
<th>{{ __('common.email') }}</th>
<th>{{ __('staff.application-type') }}</th>
<th>{{ __('common.image') }}</th>
<th>{{ __('staff.links') }}</th>
<th>{{ __('common.created_at') }}</th>
<th>{{ __('common.status') }}</th>
<th>{{ __('common.moderated-by') }}</th>
<th>{{ __('common.action') }}</th>
</tr>
</thead>
<tbody>
@forelse ($applications as $application)
<tr>
<td>{{ $application->id }}</td>
<td>
@if ($application->user === null)
N/A
@else
<x-user_tag :anon="false" :user="$application->user" />
@endif
</td>
<td>{{ $application->email }}</td>
<td>{{ $application->type }}</td>
<td>{{ $application->imageProofs->count() }}</td>
<td>{{ $application->urlProofs->count() }}</td>
<td>
<time
datetime="{{ $application->created_at }}"
title="{{ $application->created_at }}"
>
{{ $application->created_at->diffForHumans() }}
</time>
</td>
<td>
@switch($application->status)
@case(\App\Models\Application::PENDING)
<span class="application--pending">Pending</span>

@break
@case(\App\Models\Application::APPROVED)
<span class="application--approved">Approved</span>

@break
@case(\App\Models\Application::REJECTED)
<span class="application--rejected">Rejected</span>

@break
@default
<span class="application--unknown">Unknown</span>
@endswitch
</td>
<td>
@if ($application->moderated === null)
N/A
@else
<x-user_tag :anon="false" :user="$application->moderated" />
@endif
</td>
<td>
<menu class="data-table__actions">
<li class="data-table__action">
<a
class="form__button form__button--text"
href="{{ route('staff.applications.show', ['id' => $application->id]) }}"
>
{{ __('common.view') }}
</a>
</li>
</menu>
</td>
</tr>
@empty
<tr class="applications--empty">
<td colspan="10">
{{ __('common.no') }} {{ __('staff.applications') }}
</td>
</tr>
@endforelse
</tbody>
</table>
</div>
{{ $applications->links('partials.pagination') }}
</section>
@livewire('application-search')
@endsection
160 changes: 160 additions & 0 deletions resources/views/livewire/application-search.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
<section class="panelV2">
<header class="panel__header">
<h2 class="panel__heading">{{ __('staff.applications') }}</h2>
<div class="panel__actions">
<div class="panel__action">
<div class="form__group">
<select id="status" class="form__select" wire:model.live="status">
<option selected value="">All</option>
<option value="1">Approved</option>
<option value="0">Pending</option>
<option value="2">Rejected</option>
</select>
<label class="form__label form__label--floating" for="status">Status</label>
</div>
</div>
<div class="panel__action">
<div class="form__group">
<input
id="receiver"
class="form__text"
type="text"
wire:model.live="email"
placeholder=" "
/>
<label class="form__label form__label--floating" for="receiver">
{{ __('common.email') }}
</label>
</div>
</div>
<div class="panel__action">
<div class="form__group">
<select id="quantity" class="form__select" wire:model.live="perPage" required>
<option>25</option>
<option>50</option>
<option>100</option>
</select>
<label class="form__label form__label--floating" for="quantity">
{{ __('common.quantity') }}
</label>
</div>
</div>
</div>
</header>
<div class="data-table-wrapper">
<table class="data-table">
<thead>
<tr>
<th>#</th>
<th>{{ __('common.user') }}</th>
<th>{{ __('common.email') }}</th>
<th>{{ __('staff.application-type') }}</th>
<th>{{ __('common.image') }}</th>
<th>{{ __('staff.links') }}</th>
<th>{{ __('common.created_at') }}</th>
<th>{{ __('common.status') }}</th>
<th>{{ __('common.moderated-by') }}</th>
<th>{{ __('common.action') }}</th>
</tr>
</thead>
<tbody>
@forelse ($applications as $application)
<tr x-data="application" data-application-id="{{ $application->id }}">
<td>{{ $application->id }}</td>
<td>
@if ($application->user === null)
N/A
@else
<x-user_tag :anon="false" :user="$application->user" />
@endif
</td>
<td>{{ $application->email }}</td>
<td>{{ $application->type }}</td>
<td>{{ $application->imageProofs->count() }}</td>
<td>{{ $application->urlProofs->count() }}</td>
<td>
<time
datetime="{{ $application->created_at }}"
title="{{ $application->created_at }}"
>
{{ $application->created_at->diffForHumans() }}
</time>
</td>
<td>
@switch($application->status)
@case(\App\Models\Application::PENDING)
<span class="application--pending">Pending</span>

@break
@case(\App\Models\Application::APPROVED)
<span class="application--approved">Approved</span>

@break
@case(\App\Models\Application::REJECTED)
<span class="application--rejected">Rejected</span>

@break
@default
<span class="application--unknown">Unknown</span>
@endswitch
</td>
<td>
@if ($application->moderated === null)
N/A
@else
<x-user_tag :anon="false" :user="$application->moderated" />
@endif
</td>
<td>
<menu class="data-table__actions">
<li class="data-table__action">
<a
class="form__button form__button--text"
href="{{ route('staff.applications.show', ['id' => $application->id]) }}"
>
{{ __('common.view') }}
</a>
</li>
<li class="data-table__action">
<form>
<button
x-on:click.prevent="destroy"
data-b64-deletion-message="{{ base64_encode('Are you sure you want to delete this application from: ' . $application->email . '?') }}"
class="form__button form__button--text"
>
{{ __('common.delete') }}
</button>
</form>
</li>
</menu>
</td>
</tr>
@empty
<tr class="applications--empty">
<td colspan="10">{{ __('common.no') }} {{ __('staff.applications') }}</td>
</tr>
@endforelse
</tbody>
</table>
</div>
{{ $applications->links('partials.pagination') }}
<script nonce="{{ HDVinnie\SecureHeaders\SecureHeaders::nonce('script') }}">
document.addEventListener('alpine:init', () => {
Alpine.data('application', () => ({
destroy() {
Swal.fire({
title: 'Are you sure?',
text: atob(this.$el.dataset.b64DeletionMessage),
icon: 'warning',
showConfirmButton: true,
showCancelButton: true,
}).then((result) => {
if (result.isConfirmed) {
this.$wire.destroy(this.$root.dataset.applicationId);
}
});
},
}));
});
</script>
</section>
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/

use App\Http\Controllers\Staff\ApplicationController;
use App\Http\Livewire\ApplicationSearch;
use App\Http\Requests\Staff\ApproveApplicationRequest;
use App\Http\Requests\Staff\RejectApplicationRequest;
use App\Models\Application;
Expand Down Expand Up @@ -56,7 +57,7 @@
$response = $this->actingAs($this->staffUser)->get(route('staff.applications.index'));
$response->assertOk();
$response->assertViewIs('Staff.application.index');
$response->assertViewHas('applications');
$response->assertSeeLivewire(ApplicationSearch::class);
});

test('reject validates with a form request', function (): void {
Expand Down
Loading