Skip to content

Commit

Permalink
fix issue #33
Browse files Browse the repository at this point in the history
  • Loading branch information
gheorghelupu17 committed Jun 26, 2023
1 parent 6bd30c5 commit 243aedd
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 121 deletions.
29 changes: 29 additions & 0 deletions app/Http/Controllers/Ngo/VolunteerController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace App\Http\Controllers\Ngo;

use App\Http\Controllers\Controller;
use App\Models\Volunteer;
use Illuminate\Http\Request;
use Inertia\Inertia;

class VolunteerController extends Controller
{
public function index(Request $request, $status = '')
{

$volunteers = Volunteer::whereHas('projects', function ($query) {
$query->whereIn('projects.id', auth()->user()->organization->projects->pluck('id'));
})->with('projects');
if (in_array($status, ['pending', 'approved', 'rejected'])) {
$volunteers->where('status', $status);
}

return Inertia::render('AdminOng/Volunteers/Volunteers',
[
'volunteers' => $volunteers->paginate()->withQueryString(),
'status' => $status,
]
);
}
}
4 changes: 2 additions & 2 deletions app/Models/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ public function counties(): BelongsToMany
return $this->belongsToMany(County::class);
}

public function volunteers(): HasMany
public function volunteers(): BelongsToMany
{
return $this->hasMany(Volunteer::class);
return $this->belongsToMany(Volunteer::class);
}

public function stages(): BelongsToMany
Expand Down
5 changes: 5 additions & 0 deletions app/Models/Volunteer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ class Volunteer extends Model
'status',
];

protected $casts = [
'status' => 'string',
'created_at' => 'date:Y-m-d',
];

public function user(): BelongsTo
{
return $this->belongsTo(User::class);
Expand Down
24 changes: 24 additions & 0 deletions database/factories/VolunteerFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Database\Factories;

use App\Models\User;
use App\Models\Volunteer;
use Illuminate\Database\Eloquent\Factories\Factory;
use function Symfony\Component\Translation\t;

class VolunteerFactory extends Factory
{
protected $model = Volunteer::class;

public function definition(): array
{
return [
'first_name' => $this->faker->firstName,
'last_name' => $this->faker->lastName,
'email' => $this->faker->unique()->safeEmail,
'phone' => $this->faker->phoneNumber,
'status' => $this->faker->randomElement(['pending', 'approved', 'rejected'])
];
}
}
7 changes: 6 additions & 1 deletion database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use App\Models\Organization;
use App\Models\Project;
use App\Models\User;
use App\Models\Volunteer;
use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
Expand Down Expand Up @@ -48,7 +49,11 @@ public function run(): void
} else {
User::factory()->ngoAdmin()->for($organization)->create();
}
Project::factory()->for($organization)->count(10)->create();
$project = Project::factory()->for($organization)->count(10)->create();
$project->each(function ($project) {
$project->volunteers()->attach(Volunteer::factory()->count(10)->create());
});

}

for ($i = 0; $i < self::USER_BB_MANAGER_NUMBER; $i++) {
Expand Down
25 changes: 24 additions & 1 deletion resources/js/Components/templates/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,30 @@ const navigation = [
name: 'Voluntari',
href: 'admin.ong.volunteers',
route: route('admin.ong.volunteers'),
subroutes: [],
subroutes: ['admin.ong.project.add', 'admin.ong.project.edit'],
subMenu: [
{
name: 'volunteers_approved',
href: 'admin.ong.volunteers',
route: route('admin.ong.volunteers', {'status': 'approved'}),
icon: UsersIcon,
subroutes: [],
},
{
name: 'volunteers_pending',
href: 'admin.ong.volunteers',
route: route('admin.ong.volunteers', {'status': 'pending'}),
subroutes: [],
icon: UsersIcon
},
{
name: 'volunteers_rejected',
href: 'admin.ong.volunteers',
route: route('admin.ong.volunteers', {'status': 'rejected'}),
subroutes: [],
icon: UsersIcon
}
],
icon: UsersIcon,
},
{
Expand Down
148 changes: 41 additions & 107 deletions resources/js/Pages/AdminOng/Volunteers/Volunteers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,50 @@
<!-- Header -->
<DropdownLinkVue class="flex items-center gap-4">
<div class="bg-turqoise-500 w-8 h-8 rounded-lg flex items-center justify-center">
<SvgLoader class="shrink-0" name="add_white"/>
<SvgLoader class="shrink-0" name="add_white" v-if="status==='pending'"/>
<SvgLoader class="shrink-0" name="block" v-else-if="status==='rejected'"/>
<SvgLoader class="shrink-0 fill-white" name="heart_white" v-else/>
</div>
<h2 class="text-2xl font-bold text-gray-900">{{ $t('new_volunteer_requests') }}</h2>
<h2 class="text-2xl font-bold text-gray-900" v-if="status==='pending'">{{ $t('new_volunteer_requests') }}</h2>
<h2 class="text-2xl font-bold text-gray-900" v-else-if="status==='rejected'">{{ $t('rejected_requests') }}</h2>
<h2 class="text-2xl font-bold text-gray-900" v-else>{{ $t('my_volunteers') }}</h2>
</DropdownLinkVue>

<Table
class="mb-24"
:columns="requests"
:currentPage="volunteers1.current_page"
:prev="volunteers1.prev_page_url"
:next="volunteers1.next_page_url"
:links="volunteers1.links"
:currentPage="volunteers.current_page"
:prev="volunteers.prev_page_url"
:next="volunteers.next_page_url"
:links="volunteers.links"
>
<tr v-for="person in volunteers1.data" :key="person.email">
<tr v-for="person in volunteers.data" :key="person.email">
<td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-gray-900 sm:pl-6">
<div class="flex items-center gap-4">
<img v-if="person.user.image" :src="person.user.image" alt="avatar">
<img v-if="person?.user?.image" :src="person.user.image" alt="avatar">
<SvgLoader v-else class="shrink-0" name="default_avatar" />
<div>
<p class="text-sm text-gray-900 font-medium">{{ person.user.name }}</p>
<p class="text-sm text-gray-500">{{ person.user.email }}</p>
<p class="text-sm text-gray-900 font-medium">{{ person.user?.name ? person.user.name: person.first_name+' '+person.last_name }}</p>
<p class="text-sm text-gray-500">{{ person.user?.email ? person.user.email : person.email }}</p>
</div>
</div>
</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">{{ person.user.phone ? person.user.phone : '-' }}</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-900">{{ person.proiect ? person.proiect : $t('general') }}</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">{{ person.user?.phone ? person.user?.phone : person.phone }}</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-900">{{ person.projects ? person.projects.map(item=>item.name).join(', ') : $t('general') }}</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">{{ person.created_at }}</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">{{ person.role ? person.role : $t('no') }}</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">{{ person.user_id ? $t('yes') : $t('no') }}</td>
<td class="relative whitespace-nowrap py-4 pl-3 pr-4 text-right text-sm font-medium sm:pr-6 flex items-center flex-col">
<td class="relative whitespace-nowrap py-4 pl-3 pr-4 text-right text-sm font-medium sm:pr-6 flex items-center flex-col" v-if="status==='pending'">
<ModalAction
triggerModalClasses="block text-sm font-medium leadin-5 text-blue-500"
:triggerModalText="$t('accept')"
:cancelModalText="$t('cancel')"
:actionModalText="$t('accept')"
:title="$t('confirm')"
:body="`${$t('confirm_accept_text')} ${person.user.name}`"
:body="`${$t('confirm_accept_text')} ${person.user?.name}`"
actionRoute="route('admin.client.destroy', person.user.id)"
:data="volunteers1.data"
:data="volunteers.data"
/>
<ModalAction
Expand All @@ -66,116 +70,36 @@
:cancelModalText="$t('cancel')"
:actionModalText="$t('reject')"
:title="$t('confirm')"
:body="`${$t('confirm_reject_text')} ${person.user.name}`"
:body="`${$t('confirm_reject_text')} ${person.user?.name}`"
actionRoute="route('admin.client.destroy', person.user.id)"
:data="volunteers1.data"
:data="volunteers.data"
/>
</td>
</tr>
</Table>


<!-- Header -->
<div class="flex items-center justify-between">
<div class="flex items-center gap-4">
<div class="bg-turqoise-500 w-8 h-8 rounded-lg flex items-center justify-center">
<SvgLoader class="shrink-0 fill-white" name="heart_white"/>
</div>
<h2 class="text-2xl font-bold text-gray-900">{{ $t('my_volunteers') }}</h2>
</div>

<SecondaryButton
class="py-2.5 flex items-center justify-center gap-4"
>
<SvgLoader class="shrink-0" name="download" />
{{ $t('download_table') }}
</SecondaryButton>
</div>

<Table
class="mb-24"
:columns="requests"
:currentPage="volunteers2.current_page"
:prev="volunteers2.prev_page_url"
:next="volunteers2.next_page_url"
:links="volunteers2.links"
>
<tr v-for="person in volunteers2.data" :key="person.email">
<td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-gray-900 sm:pl-6">
<div class="flex items-center gap-4">
<img v-if="person.user.image" :src="person.user.image" alt="avatar">
<SvgLoader v-else class="shrink-0" name="default_avatar" />
<div>
<p class="text-sm text-gray-900 font-medium">{{ person.user.name }}</p>
<p class="text-sm text-gray-500">{{ person.user.email }}</p>
</div>
</div>
</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">{{ person.user.phone ? person.user.phone : '-' }}</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-900">{{ person.proiect ? person.proiect : $t('general') }}</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">{{ person.created_at }}</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">{{ person.role ? person.role : $t('no') }}</td>


<td class="relative whitespace-nowrap py-4 pl-3 pr-4 text-right text-sm font-medium sm:pr-6 flex items-center flex-col">
</td >
<td class="relative whitespace-nowrap py-4 pl-3 pr-4 text-right text-sm font-medium sm:pr-6 flex items-center flex-col" v-else-if="status==='rejected'">
<ModalAction
triggerModalClasses="block text-sm font-medium leadin-5 text-blue-500"
:triggerModalText="$t('elimin')"
:triggerModalText="$t('delete')"
:cancelModalText="$t('cancel')"
:actionModalText="$t('elimin')"
:actionModalText="$t('delete')"
:title="$t('confirm')"
:body="`${$t('confirm_elimin_text')} ${person.user.name}`"
:body="`${$t('confirm_delete_text')} ${person.user?.name}`"
actionRoute="route('admin.client.destroy', person.user.id)"
:data="volunteers2.data"
:data="volunteers.data"
/>
</td>
</tr>
</Table>

<!-- Header -->
<div class="flex items-center gap-4">
<div class="bg-turqoise-500 w-8 h-8 rounded-lg flex items-center justify-center">
<SvgLoader class="shrink-0" name="block"/>
</div>
<h2 class="text-2xl font-bold text-gray-900">{{ $t('rejected_requests') }}</h2>
</div>

<Table
:columns="requests"
:currentPage="volunteers3.current_page"
:prev="volunteers3.prev_page_url"
:next="volunteers3.next_page_url"
:links="volunteers3.links"
>
<tr v-for="person in volunteers3.data" :key="person.email">
<td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-gray-900 sm:pl-6">
<div class="flex items-center gap-4">
<img v-if="person.user.image" :src="person.user.image" alt="avatar">
<SvgLoader v-else class="shrink-0" name="default_avatar" />
<div>
<p class="text-sm text-gray-900 font-medium">{{ person.user.name }}</p>
<p class="text-sm text-gray-500">{{ person.user.email }}</p>
</div>
</div>
</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">{{ person.user.phone ? person.user.phone : '-' }}</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-900">{{ person.proiect ? person.proiect : $t('general') }}</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">{{ person.created_at }}</td>
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">{{ person.role ? person.role : $t('no') }}</td>


<td class="relative whitespace-nowrap py-4 pl-3 pr-4 text-right text-sm font-medium sm:pr-6 flex items-center flex-col">
<td class="relative whitespace-nowrap py-4 pl-3 pr-4 text-right text-sm font-medium sm:pr-6 flex items-center flex-col" v-else>
<ModalAction
triggerModalClasses="block text-sm font-medium leadin-5 text-blue-500"
:triggerModalText="$t('delete')"
:cancelModalText="$t('cancel')"
:actionModalText="$t('delete')"
:title="$t('confirm')"
:body="`${$t('confirm_delete_text')} ${person.user.name}`"
:body="`${$t('confirm_delete_text')} ${person.user?.name} `"
actionRoute="route('admin.client.destroy', person.user.id)"
:data="volunteers3.data"
/>
</td>
</tr>
</Table>
</div>
Expand All @@ -195,6 +119,7 @@
import Table from '@/Components/templates/Table.vue';
import ModalAction from '@/Components/modals/ModalAction.vue';
import SecondaryButton from '@/Components/buttons/SecondaryButton.vue';
import {onMounted} from "vue";
const flash = {
success_message:'',
Expand All @@ -203,6 +128,15 @@
const requests = ['Nume', 'Telefon', 'Proiect', 'Data Inscriere', 'Utilizator'];
const props = defineProps({
volunteers: Object,
flash: Object,
status: String,
});
onMounted(() => {
console.log(props.volunteers)
});
const volunteers1 = {
"current_page": 2,
"data": [
Expand Down
10 changes: 3 additions & 7 deletions resources/js/locales/ro.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,7 @@ export default {
"parteners": "Parteneri",
"faqs_title": "Intrebări frecvente",
"contact_us": "Contactează-ne",
"organization_arr":{
'status': {
'pending': 'În așteptare',
'active': 'Activ',
'disabled': 'Inactiv',
}
}
'volunteers_rejected': 'Voluntari respinși',
'volunteers_approved': 'Voluntarii mei',
'volunteers_pending': 'Voluntari în așteptare',
}
4 changes: 1 addition & 3 deletions routes/volunteers.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@
use Inertia\Inertia;

Route::prefix('ong')->middleware('auth')->group(function () {
Route::get('voluntari', function () {
return Inertia::render('AdminOng/Volunteers/Volunteers');
})->name('admin.ong.volunteers');
Route::get('voluntari/{status?}', [\App\Http\Controllers\Ngo\VolunteerController::class, 'index'])->name('admin.ong.volunteers');;
});

0 comments on commit 243aedd

Please sign in to comment.