Skip to content
This repository has been archived by the owner on Apr 23, 2024. It is now read-only.

Commit

Permalink
dev: ContactForm admin panel and ContactFormSeeder
Browse files Browse the repository at this point in the history
  • Loading branch information
na-teag committed Apr 16, 2024
1 parent e6ae666 commit 892af51
Show file tree
Hide file tree
Showing 7 changed files with 322 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,14 @@ public function getContacts(): JsonResponse
return response()->json($contacts);
}

/**
* remove the contact forms.
*
* @return Response
*/
public function removeContact(): Response
{
return response(status: 200);
}

}
37 changes: 37 additions & 0 deletions database/seeders/ContactFormSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Database\Seeders;

use App\Models\ContactForm;
use App\Models\User;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class ContactFormSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
//$user = User::find(0);

ContactForm::create([
"id" => 0,
/*"first_name" => $user->first_name,
"last_name" => $user->last_name,
"email" => $user->email,
"gender" => $user->gender,
"job_id" => $user->job_id,
"birth" => $user->birth,*/
"first_name" => "Steve",
"last_name" => "Rogers",
"email" => "steve@minecraft.block",
"gender" => 0,
"job_id" => 1,
"birth" => "1970-01-01",
"subject" => "This website is so cool",
"content" => "This is just a supportive message to tell you just how awesome your website is.",
]);
}
}
1 change: 1 addition & 0 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ public function run(): void
$this->call(JobSeeder::class);
$this->call(ProductSeeder::class);
$this->call(UserSeeder::class);
$this->call(ContactFormSeeder::class);
}
}
115 changes: 115 additions & 0 deletions public/css/admin_contacts.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
main {
display: flex;
flex-direction: column;
}

div.manager {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 3vw;

flex: 1 1 auto;
}

h1 {
margin-top: 0;
margin-left: auto;
margin-right: auto;
width: fit-content;
}

/* contact list */

div.manager div#contact_list {
background: rgba(0, 0, 0, 0.6);
padding: 1vw;
}

div.manager div#contact_details {
background: rgba(73, 35, 1, 0.6);
}

div.manager hr {
margin: 0.8vw 0;
}

/* Seach bar */

.search_container {
display: flex;
align-items: center;
max-width: 70%;
margin: 0 auto;

background: rgba(0, 0, 0, 0.4);
}

.search_icon {
max-width: 4%;

color: white;
padding: 0.5vw;
}

.search_input {
flex: 1;
background: none;
border: none;
padding: 0.5vw;

color:white;
font-family: 'Minecraft', sans-serif;
font-size: 100%;
}

.search_input:focus {
outline: none;
}

/* contact table */

div#contact_table table {
width: 100%;
border-collapse: collapse;
}

div#contact_table th, div#contact_table td {
padding: 0.1vw;
text-align: center;
}

div#contact_table thead {
background: rgba(0, 0, 0, 0.65);
}

div#contact_table tbody {
background: rgba(0, 0, 0, 0.3);
}

div#contact_table tbody td {
padding: 0.4vw;
}

div#contact_table tbody tr:hover {
background: rgba(0, 0, 0, 0.5);
}

/* contact details */

div#contact_details {
display: flex;
flex-direction: column;
padding: 1vw;
}

/* Not loaded */

div#contact_details div#contact_details_not_loaded {
margin: auto;
}

/* Loaded */

div#contact_details div#contact_details_loaded {
margin: auto;
}
55 changes: 55 additions & 0 deletions public/js/admin_contacts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Seach system
document.querySelector('.search_input').addEventListener('input', function() {
let searchValue = this.value.toLowerCase();
let rows = document.querySelectorAll('#contact_table tbody tr');
rows.forEach(function(row) {
let contact = row.querySelector('td:nth-child(2)').textContent.toLowerCase();
if (contact.indexOf(searchValue) > -1) {
row.style.display = '';
} else {
row.style.display = 'none';
}
});
});

// contact details system
let not_loaded_div = document.querySelector('#contact_details_not_loaded');
let loaded_div = document.querySelector('#contact_details_loaded');

let contact_id = document.querySelector('#contact_id');
let email_field = document.querySelector('#email');
let first_name_field = document.querySelector('#first_name');
let last_name_field = document.querySelector('#last_name');
let birthday_field = document.querySelector('#birthday');
let gender_field = document.querySelector('#gender');
let job_field = document.querySelector('#job');
let subject_field = document.querySelector('#subject');
let content_field = document.querySelector('#content');
let contact_id_delete = document.querySelector('#contact_id_delete');

function displayContactDetails(contact) {
loaded_div.classList.remove('hidden');
not_loaded_div.classList.add('hidden');

// Set values
contact_id.value = contact.id;
email_field.value = contact.email;
first_name_field.value = contact.first_name;
last_name_field.value = contact.last_name;
birthday_field.value = contact.birth;
switch (contact.gender) {
case 0:
gender_field = "Homme";
break;
case 1:
gender_field = "Femme";
break;
default:
gender_field = "Autre";
break;
}
job_field.value = contact.job_id;
subject_field.value = contact.subject;
content_field.value = contact.content;
contact_id_delete.value = contact.id;
}
99 changes: 99 additions & 0 deletions resources/views/admin_contacts.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<h1>Gestionnaire formulaires de contact</h1>
@foreach($errors->all() as $error)
<div class="notif error">
<img src="{{ asset('img/white-cross.png') }}" alt="Croix blanche" onclick="closeWidget(this.parentNode)"/>
<p>{{$error}}</p>
</div>
@endforeach
<div class=manager>
<div id="contacts_list">
<div class="search_container">
<img class="search_icon" src="{{ asset('img/search-icon.svg') }}" alt="Search icon">
<input type="text" class="search_input" placeholder="Rechercher...">
</div>
<hr>
<div id="contact_table">
<table>
<thead>
<tr>
<th>Id</th>
<th>Subject</th>
</tr>
</thead>

<tbody>
@foreach(\App\Models\ContactForm::all() as $contact)
<tr onclick="displayContactDetails({{ $contact }})">
<td>{{ $contact->id }}</td>
<td>{{ $contact->subject }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>

<div id="contact_details">
<div id="contact_details_not_loaded">
<h2>Veuillez sélectionner un utilisateur</h2>
</div>
<div id="contact_details_loaded" class="hidden">

<table>
<tr>
<td>Prénom:</td><td id="first_name"></td>
</tr>
<tr>
<td>Nom:</td><td id="last_name"></td>
</tr>
<tr>
<td>mail:</td><td id="email"></td>
</tr>
<tr>
<td>Genre:</td><td id="gender"></td>
</tr>
<tr>
<td>Date de naissance:</td><td id="birthday"></td>
</tr>
<tr>
<td>Métier:</td><td id="job"></td>
</tr>
</table>

<table>
<tr>
<td id="subject"></td>
</tr>
<tr>
<td id="content"></td>
</tr>
</table>

<form action="/admin/contact/reply" method="post" autocomplete="off">
@csrf

<input type="hidden" id="contact_id" name="id"/>

<!-- response -->
<div class="contact_details_field">
<label for="mailBody">Réponse :</label>
<textarea id="response" name="mailBody" required/>
</div>

<!-- Submit -->
<div class="contact_details_field">
<input type="submit" value="Envoyer"/>
</div>
</form>

<!-- Delete button -->
<div class="contact_details_field">
<form action="/admin/contact/remove" method="post">
@csrf
<input type="hidden" id="contact_id_delete" name="id"/>
<input type="submit" value="Supprimer"/>
</form>
</div>
</div>
</div>
</div>
5 changes: 5 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@
"page_to_load" => "admin_users",
"title" => "Gestion utilisateurs"
]);})->middleware("admin");
Route::get('/admin/contacts', function () {return view('application', [
"page_to_load" => "admin_contacts",
"title" => "Gestion formulaires de contact"
]);})->middleware("admin");


Route::post("/auth/login", [AuthController::class, "login"]);
Expand Down Expand Up @@ -140,3 +144,4 @@
Route::post("/admin/user/resetPassword", [AdminController::class, "resetPassword"])->middleware(["admin", "verified"]);
Route::post("/admin/contact/get", [AdminController::class, "getContacts"])->middleware(["admin", "verified"]);
Route::post("/admin/contact/reply", [AdminController::class, "replyContact"])->middleware(["admin", "verified"]);
Route::post("/admin/contact/remove", [AdminController::class, "removeContact"])->middleware(["admin", "verified"]);

0 comments on commit 892af51

Please sign in to comment.