Compare commits

...

2 commits

Author SHA1 Message Date
Anna-Sara Sélea
f68a18c6b3 Added comment to customer model. Comment in frontend 2025-09-21 08:43:11 +02:00
Anna-Sara Sélea
b4ff1ee8fa Added comment to customer model. Comment in frontend 2025-09-21 08:40:38 +02:00
6 changed files with 92 additions and 2 deletions

View file

@ -82,6 +82,24 @@ class CustomerController extends Controller
return redirect('customer/' . $customer->id); return redirect('customer/' . $customer->id);
} }
/**
* Update the specified resource in storage.
*/
public function updateComment(Request $request)
{
$request->validate([
'customer_id' => 'required',
'comment' => 'required',
]);
$customer = Customer::findOrFail($request->customer_id);
$customer->comment = $request->comment;
$customer->save();
return redirect('customer/' . $customer->id);
}
/** /**
* Remove the specified resource from storage. * Remove the specified resource from storage.
*/ */

View file

@ -20,6 +20,7 @@ class Customer extends Model
'amount used', 'amount used',
'deposit', 'deposit',
'give_leftover', 'give_leftover',
'comment'
]; ];
/** /**

View file

@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('customers', function (Blueprint $table) {
$table->mediumText('comment')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('customers', function (Blueprint $table) {
$table->dropColumn('comment');
});
}
};

View file

@ -11,6 +11,15 @@
color: var(--button-link-color); color: var(--button-link-color);
} }
.button.is-info {
border: 1px solid var(--button-link-background-color);
color: var(--button-link-background-color);
&:hover {
border: 2px solid var(--button-link-background-color);
}
}
.button.letter { .button.letter {
background-color: #fff; background-color: #fff;
color: #000; color: #000;

View file

@ -1,5 +1,6 @@
import TextInput from '@/Components/TextInput'; import TextInput from '@/Components/TextInput';
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout'; import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout';
import { Textarea } from '@headlessui/react';
import { Head, useForm } from '@inertiajs/react'; import { Head, useForm } from '@inertiajs/react';
import axios from 'axios'; import axios from 'axios';
import { FormEventHandler } from 'react'; import { FormEventHandler } from 'react';
@ -12,6 +13,7 @@ interface CustomerProps {
amount_left: number amount_left: number
give_leftover: number give_leftover: number
guardian_name: string guardian_name: string
comment: string;
purchases: [{ purchases: [{
id: number id: number
amount: number amount: number
@ -29,7 +31,8 @@ export default function Customer({customer}: CustomerProps) {
amount: "", amount: "",
customer_id: customer.id, customer_id: customer.id,
deposit: "", deposit: "",
id: customer.id id: customer.id,
comment: ""
}); });
const submit: FormEventHandler = (e) => { const submit: FormEventHandler = (e) => {
@ -46,6 +49,12 @@ export default function Customer({customer}: CustomerProps) {
}); });
} }
const updateComment: FormEventHandler = (e) => {
e.preventDefault()
post(route('update_comment'), {
});
}
const deleteCustomer = (id: string | number) => { const deleteCustomer = (id: string | number) => {
axios.delete('/api/customer/' + id) axios.delete('/api/customer/' + id)
.then(response => { .then(response => {
@ -119,6 +128,30 @@ export default function Customer({customer}: CustomerProps) {
</form> </form>
</div> </div>
<div className="box">
<h2 className='title is-4'>Kommentar</h2>
<form onSubmit={updateComment}>
<div className="field">
<div className="control">
<textarea
required
className="textarea"
name="comment"
defaultValue={customer.comment}
value={data.comment}
//placeholder="Kommentar"
onChange={(e) => setData('comment', e.target.value)}
/>
</div>
</div>
<div className="field is-grouped">
<div className="control">
<button className="button">Spara</button>
</div>
</div>
</form>
</div>
<details className="box"> <details className="box">
<summary className='title is-4 my-3'> <summary className='title is-4 my-3'>
<span>Köp</span> <span>Köp</span>
@ -160,7 +193,7 @@ export default function Customer({customer}: CustomerProps) {
</div> </div>
</details> </details>
</div> </div>
<button onClick={() => deleteCustomer(customer.id)} className="button mt-4 is-danger is-outlined is-small"> <button onClick={() => deleteCustomer(customer.id)} className="button mt-4 mr-3 is-danger is-outlined is-small">
<span>Radera deltagare</span> <span>Radera deltagare</span>
</button> </button>
</div> </div>

View file

@ -10,6 +10,7 @@ Route::post('register_customer', [CustomerController::class, 'store'])->name('re
Route::middleware('auth:sanctum')->group(function () { Route::middleware('auth:sanctum')->group(function () {
Route::post('register_deposit', [DepositController::class, 'store'])->name('register_deposit'); Route::post('register_deposit', [DepositController::class, 'store'])->name('register_deposit');
Route::post('update_comment', [CustomerController::class, 'updateComment'])->name('update_comment');
Route::post('register_purchase', [PurchaseController::class, 'store'])->name('register_purchase'); Route::post('register_purchase', [PurchaseController::class, 'store'])->name('register_purchase');
Route::delete('customer/{id}', [CustomerController::class, 'destroy'])->name('delete_customer'); Route::delete('customer/{id}', [CustomerController::class, 'destroy'])->name('delete_customer');
}); });