Skip to content

Commit

Permalink
Add decision form
Browse files Browse the repository at this point in the history
  • Loading branch information
andyksaw committed Jan 11, 2025
1 parent 23117c9 commit 8b6bca9
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Domains\BuilderRankApplications\Notifications\BuilderRankAppApprovedNotification;
use App\Models\BuilderRankApplication;
use App\Models\Group;
use Illuminate\Support\Facades\DB;

class ApproveBuildRankApplication
{
Expand All @@ -14,15 +15,25 @@ public function execute(
int $promoteGroupId,
): BuilderRankApplication {
$application = BuilderRankApplication::find($applicationId);
$promoteGroup = Group::find($promoteGroupId);

abort_if($application->isReviewed(), 409);

$application->status = ApplicationStatus::APPROVED->value;
$application->closed_at = now();
$application->save();

$promoteGroup = Group::find($promoteGroupId);
$application->account->groups()->attach($promoteGroup->getKey());
DB::transaction(function () use ($application, $promoteGroup) {
$application->status = ApplicationStatus::APPROVED->value;
$application->closed_at = now();
$application->save();

$updatedGroupIds = $application
->account
->groups()
->where('group_type', '!=', 'build')
->get()
->map(fn ($it) => $it->getKey())
->push($promoteGroup->getKey());

$application->account->groups()->sync($updatedGroupIds);
});

$application->account->notify(
new BuilderRankAppApprovedNotification(
Expand Down
2 changes: 1 addition & 1 deletion resources/js/review/Pages/BanAppeals/BanAppealShow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ function submit() {
class="block p-2.5 w-full text-sm text-gray-900 bg-gray-50 rounded-lg border border-gray-300 focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500"
></textarea>
<span class="block mt-2 text-xs text-gray-400">
This is the message email to the player regarding their application. <br />
This is the message emailed to the player regarding their application. <br />
<strong>Please include the reasoning for your decision</strong>
</span>
<div v-if="form.errors.decision_note" class="text-xs text-red-500 font-bold mt-2">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { Head, useForm } from '@inertiajs/vue3'
import { Head } from '@inertiajs/vue3'
import Card from '../../../manage/Components/Card.vue'
import BackButton from '../../../manage/Components/BackButton.vue'
import MinecraftAvatar from '../../../manage/Components/MinecraftAvatar.vue'
Expand All @@ -16,6 +16,7 @@ import Pill from '../../../manage/Components/Pill.vue'
import type { Group } from '../../../manage/Data/Group'
import AwaitingDecisionAlert from './Partials/AwaitingDecisionAlert.vue'
import BuilderRankDecision from './Partials/BuilderRankDecision.vue'
import BuilderRankDecisionForm from './Partials/BuilderRankDecisionForm.vue'
interface Props {
application: BuilderRankApplication,
Expand All @@ -24,12 +25,6 @@ interface Props {
}
const props = defineProps<Props>()
const form = useForm({
status: null,
promote_group: null,
decision_note: null,
})
const hasDecision = computed(() => props.application.status !== BuilderRankApplicationStatus.pending)
const waitingTime = computed(() => {
Expand All @@ -41,10 +36,6 @@ const waitingTime = computed(() => {
const player = computed(() => props.application.account?.minecraft_account?.at(0))
const alts = computed(() => props.application.account?.minecraft_account?.slice(1) ?? [])
function submit() {
form.put('/review/ban-appeals/' + props.application.id)
}
</script>

<template>
Expand Down Expand Up @@ -150,12 +141,7 @@ function submit() {

<section>
<AwaitingDecisionAlert
v-if="application.status === BuilderRankApplicationStatus.pending"
class="mb-4"
/>
<BuilderRankDecision
v-else
:application="application"
v-if="!hasDecision"
class="mb-4"
/>

Expand Down Expand Up @@ -199,61 +185,16 @@ function submit() {
</div>
</Card>

<Card v-if="!hasDecision">
<div class="p-4 border-b border-gray-200">
<h2 class="font-bold">Decision</h2>
</div>

<form @submit.prevent="submit" class="p-4">
<ErrorAlert v-if="form.hasErrors" :errors="form.errors" class="mb-4"/>

<div class="space-y-6">
<div>
<div class="mb-4">
<label for="activated" class="text-xs text-gray-700 font-bold">Promote to...</label>
<select
v-model="form.promote_group"
id="activated"
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
>
<option :value="null">Select a build group...</option>
<option v-for="group in buildGroups" :value="group.group_id">{{ group.name }}</option>
</select>
</div>
</div>
<div>
<label for="decision_note" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">
Message to Player
</label>
<textarea
v-model="form.decision_note"
id="additional_info"
rows="8"
class="block p-2.5 w-full text-sm text-gray-900 bg-gray-50 rounded-lg border border-gray-300 focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500"
></textarea>
<span class="block mt-2 text-xs text-gray-400">
This is the message email to the player regarding their application. <br />
<strong>Please include the reasoning for your decision</strong>
</span>
<div v-if="form.errors.decision_note" class="text-xs text-red-500 font-bold mt-2">
{{ form.errors.decision_note }}
</div>
</div>
</div>

Applications cannot be re-opened after approving or denying.
Please finalise the decision before pressing a button

<FilledButton
variant="danger"
:disabled="form.processing"
type="submit"
class="mt-8"
>
Finish and Close
</FilledButton>
</form>
</Card>
<BuilderRankDecision
v-if="hasDecision"
:application="application"
class="mb-4"
/>
<BuilderRankDecisionForm
v-else
:application="application"
:build-groups="buildGroups"
/>
</section>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<script setup lang="ts">
import Card from '../../../../manage/Components/Card.vue'
import { useForm } from '@inertiajs/vue3'
import { BuilderRankApplication } from '../../../../manage/Data/BuilderRankApplication'
import FilledButton from '../../../../manage/Components/FilledButton.vue'
import ErrorAlert from '../../../../manage/Components/ErrorAlert.vue'
import { ref } from 'vue'
import { Group } from '../../../../manage/Data/Group'
interface Props {
application: BuilderRankApplication,
buildGroups: Group[],
}
const props = defineProps<Props>()
const form = useForm({
status: null,
promote_group: null,
deny_reason: null,
})
enum Decision {
approve,
deny,
}
const decision = ref<Decision|null>(null)
function approve() {
form.post('/review/builder-ranks/' + props.application.id + '/approve')
}
function deny() {
form.post('/review/builder-ranks/' + props.application.id + '/deny')
}
</script>

<template>
<div>
<Card>
<div class="p-4">
<h2 class="font-bold">Council Decision</h2>
</div>

<div class="p-4 border-t border-gray-200 flex flex-col gap-2">
<label for="approve">
<input
id="approve"
type="radio"
name="decision"
v-model="decision"
:value="Decision.approve"
class="mr-1"
/>
Approve
</label>
<label for="deny">
<input
id="deny"
type="radio"
name="decision"
v-model="decision"
:value="Decision.deny"
class="mr-1"
/>
Deny
</label>

<div class="mt-4 text-sm">
<strong>Applications cannot be re-opened after submitting this form.</strong><br />
Please finalize the decision with other council members before proceeding.
</div>
</div>

<form @submit.prevent class="p-4 border-t border-gray-200" v-if="decision != null">
<ErrorAlert v-if="form.hasErrors" :errors="form.errors" class="mb-4"/>

<template v-if="decision === Decision.approve">
<div class="space-y-6">
<div class="mb-4">
<label for="activated" class="text-xs text-gray-700 font-bold">Promote to...</label>
<select
v-model="form.promote_group"
id="activated"
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
>
<option :value="null">Select a build group...</option>
<option v-for="group in buildGroups" :value="group.group_id">{{ group.name }}</option>
</select>
</div>
</div>

<FilledButton
variant="danger"
@click="approve"
:disabled="form.processing"
class="mt-8"
>
Promote and Close
</FilledButton>
</template>

<template v-if="decision === Decision.deny">
<div>
<label for="deny_reason" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">
Denial Reason & Feedback
</label>
<textarea
v-model="form.deny_reason"
id="deny_reason"
rows="10"
class="block p-2.5 w-full text-sm text-gray-900 bg-gray-50 rounded-lg border border-gray-300 focus:ring-primary-500 focus:border-primary-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-primary-500 dark:focus:border-primary-500"
></textarea>
<span class="block mt-2 text-xs text-gray-400">
This is the message emailed to the player regarding their application.<br />
<strong>Please include the reasoning for the decision, and if possible, feedback on their build</strong>
</span>
</div>

<FilledButton
variant="danger"
@click="deny"
:disabled="form.processing"
class="mt-8"
>
Deny and Close
</FilledButton>
</template>
</form>
</Card>
</div>
</template>

0 comments on commit 8b6bca9

Please sign in to comment.