- add send CV status

This commit is contained in:
Kamil Niemczycki 2023-08-04 16:25:09 +02:00
parent 6a033d108c
commit 2a2869e2c6
Signed by: kamilniemczycki
GPG Key ID: 04D4E2012F969213
10 changed files with 104 additions and 11 deletions

View File

@ -56,6 +56,17 @@ class CVController extends Controller
->with('success', 'Utworzono nowe CV dla firmy ' . $request->get('recipient'));
}
public function updateSendStatus(CV $cv): RedirectResponse
{
$cv->update([
'sended' => true,
'sended_timestamp' => now()
]);
return redirect()
->route('admin.cv.show', ['cv' => $cv])
->with('success', 'Status wysłania ustawiono jako "wysłano".');
}
public function edit(CV $cv): InertiaResponse
{
return inertia('CV/Edit', [
@ -65,16 +76,30 @@ class CVController extends Controller
public function update(CVRequest $request, CV $cv): RedirectResponse
{
$cv->update([
'recipient' => $request->get('recipient'),
'email' => $request->get('email'),
'phone_number' => $request->get('phone_number'),
'locations' => ($locations = $request->get('locations')) === [''] ? [] : $locations,
'mission' => ($mission = $request->get('mission')) === [''] ? [] : $mission,
'rodo' => ($rodo =$request->get('rodo')) === '' ? null : $rodo,
'position' => $request->get('position'),
'notes' => $request->get('notes'),
$toUpdate = [
'recipient' => $request->get('recipient'),
'email' => $request->get('email'),
'phone_number' => $request->get('phone_number'),
'locations' => ($locations = $request->get('locations')) === [''] ? [] : $locations,
'mission' => ($mission = $request->get('mission')) === [''] ? [] : $mission,
'rodo' => ($rodo =$request->get('rodo')) === '' ? null : $rodo,
'position' => $request->get('position'),
'notes' => $request->get('notes'),
];
if ($cv->sended && ! $request->boolean('sended')) {
$toUpdate = array_merge($toUpdate, [
'sended' => false,
'sended_timestamp' => null,
]);
} else if (! $cv->sended && $request->boolean('sended')) {
$toUpdate = array_merge($toUpdate, [
'sended' => true,
'sended_timestamp' => now(),
]);
}
$cv->update($toUpdate);
return redirect()
->back()
->with('success', 'Zaktualizowano CV dla firmy ' . $request->get('recipient'));

View File

@ -19,6 +19,19 @@ class CVRequest extends FormRequest
'rodo' => 'nullable|string',
'position' => 'nullable|string',
'notes' => 'nullable|string',
'sended' => 'nullable|boolean',
];
}
protected function prepareForValidation(): void
{
$this->merge([
'sended' => $this->toBoolean($this->sended),
]);
}
private function toBoolean($booleable): bool
{
return filter_var($booleable, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
}
}

View File

@ -23,7 +23,7 @@ class ProjectRequest extends FormRequest
'project_url' => 'nullable|string',
'project_version' => 'nullable|string',
'description' => 'nullable|string',
'description' => 'required|string|min:3',
'visible' => 'required|boolean'
];
}

View File

@ -21,6 +21,10 @@ class FullCVResource extends JsonResource
'locations' => $this->locations,
'views' => $this->resource->info()->select('id')->get()->count(),
'registeredViews' => $this->views,
'sended' => [
'status' => $this->sended,
'datetime' => $this->sended_timestamp?->format('d-m-Y H:i:s'),
],
'position' => $this->position,
'mission' => explode(PHP_EOL, $this->mission ?? '', 5),
'rodo' => $this->rodo,

View File

@ -21,6 +21,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
* @property string|null $position
* @property string|null $notes
* @property int $views
* @property bool $sended
*/
class CV extends Model
{
@ -31,6 +32,8 @@ class CV extends Model
protected $casts = [
'locations' => 'array',
'views' => 'integer',
'sended' => 'boolean',
'sended_timestamp' => 'datetime',
];
protected function phoneNumber(): Attribute

View File

@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('cvs', function (Blueprint $table) {
$table->boolean('sended')->nullable()->default(false)->after('views');
$table->timestamp('sended_timestamp')->nullable()->after('sended');
});
}
public function down(): void
{
Schema::table('cvs', function (Blueprint $table) {
$table->dropColumn('sended');
$table->dropColumn('sended_timestamp');
});
}
};

View File

@ -40,6 +40,7 @@ const form = useForm({
rodo: props.cv.rodo,
position: props.cv.position,
notes: props.cv.notes,
sended: props.cv.sended.status,
});
function updateCV() {
@ -128,6 +129,12 @@ function updateCV() {
v-model="form.rodo"
:error="form.errors.rodo"
/>
<Input
id="sended"
label="Wysłany"
type="checkbox"
v-model="form.sended"
/>
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-3 sm:gap-2 items-center">
<InertiaLink
as="button"

View File

@ -1,5 +1,6 @@
<script setup>
import { computed } from 'vue';
import { router } from '@inertiajs/inertia';
const props = defineProps({
cv: {
@ -21,6 +22,15 @@ const cvNotes = computed(() => {
<template>
<InertiaHead title="Szczegóły CV" />
<div class="px-3 py-2">
<InertiaLink
v-if="!cv.sended.status"
as="button"
method="post"
:href="`/dashboard/cv/${cv.token}/sended`"
class="w-full px-0.5 py-1 rounded-lg bg-[#436da7] border-4 border-[#436da7] text-white text-lg hover:bg-transparent hover:text-[#436da7]"
title="Ustaw jako wysłane">Ustaw jako wysłane do odbiorcy.</InertiaLink>
</div>
<div class="p-4">
<header class="flex justify-between items-center pb-4">
<div class="flex items-center gap-2">
@ -52,6 +62,9 @@ const cvNotes = computed(() => {
><FontAwesomeIcon :icon="['fas', 'trash']" /><span class="hidden sm:inline-block">Usuń</span></InertiaLink>
</div>
</header>
<div v-if="cv.sended.status" class="max-w-screen-lg my-2 lg:mx-auto px-2 py-3 rounded-md bg-yellow-100 text-yellow-600 text-center">
CV jest oznaczone jako wysłane - {{ cv.sended.datetime }}
</div>
<div class="mb-4">
<header>
<h2 class="text-2xl font-roboto font-light pb-3">Podstawowe informacje</h2>

View File

@ -33,7 +33,7 @@ defineProps({
</nav>
</div>
</header>
<div v-if="messages?.info" class="max-w-screen-lg mx-2 lg:mx-auto mt-2 px-2 py-3 rounded-md bg-yellow-100 text-yellow-600 text-center">
<div v-if="messages?.info" class="max-w-screen-lg mx-2 lg:mx-auto mt-2 px-2 py-3 rounded-md bg-yellow-100 text-yellow-600 text-center">
{{ messages.info }}
</div>
<div v-if="messages?.error" class="max-w-screen-lg mx-2 lg:mx-auto mt-2 px-2 py-3 rounded-md bg-red-100 text-red-600 text-center">

View File

@ -22,6 +22,8 @@ Route::name('admin.')->group(function () {
->name('store');
Route::get('{cv}', 'CVController@show')
->name('show');
Route::post('{cv}/sended', 'CVController@updateSendStatus')
->name('sended');
Route::post('', 'CVController@store')
->name('store');
Route::get('{cv}/edit', 'CVController@edit')