Skip to content

Commit

Permalink
fix issue #34 fix #35 fix #36
Browse files Browse the repository at this point in the history
  • Loading branch information
gheorghelupu17 committed Jun 26, 2023
1 parent 33bb1f4 commit 5da562a
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 54 deletions.
24 changes: 24 additions & 0 deletions app/Http/Controllers/Ngo/VolunteerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,28 @@ public function index(Request $request, $status = '')
]
);
}

public function approve(Request $request, $id)
{
$volunteer = Volunteer::findOrFail($id);
$volunteer->status = 'approved';
$volunteer->save();
return redirect()->back()->with('success', 'Voluntarul a fost aprobat cu succes');
}

public function reject(Request $request, $id)
{
$volunteer = Volunteer::findOrFail($id);
$volunteer->status = 'rejected';
$volunteer->save();
return redirect()->back()->with('success', 'Voluntarul a fost respins cu succes');
}

public function delete(Request $request, $id)
{
$volunteer = Volunteer::findOrFail($id);
$projectsIds =$request->get('project_ids',[]);
$volunteer->projects()->detach($projectsIds);
return redirect()->back()->with('success', 'Voluntarul a fost sters cu succes');
}
}
164 changes: 121 additions & 43 deletions resources/js/Components/modals/ModalAction.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,31 @@
<Teleport to="body">
<TransitionRoot as="template" :show="open">
<Dialog as="div" class="relative z-50" @close="open = false">
<TransitionChild as="template" enter="ease-out duration-300" enter-from="opacity-0" enter-to="opacity-100" leave="ease-in duration-200" leave-from="opacity-100" leave-to="opacity-0">
<div class="fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity" />
<TransitionChild as="template" enter="ease-out duration-300" enter-from="opacity-0"
enter-to="opacity-100" leave="ease-in duration-200" leave-from="opacity-100"
leave-to="opacity-0">
<div class="fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity"/>
</TransitionChild>

<div class="fixed inset-0 z-10 overflow-y-auto">
<div class="flex min-h-full items-end justify-center p-4 text-center sm:items-center sm:p-0">
<TransitionChild as="template" enter="ease-out duration-300" enter-from="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95" enter-to="opacity-100 translate-y-0 sm:scale-100" leave="ease-in duration-200" leave-from="opacity-100 translate-y-0 sm:scale-100" leave-to="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95">
<DialogPanel class="relative transform overflow-hidden rounded-lg bg-white px-4 pb-4 pt-5 text-left shadow-xl transition-all sm:my-8 sm:w-full sm:max-w-lg sm:p-6">
<TransitionChild as="template" enter="ease-out duration-300"
enter-from="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
enter-to="opacity-100 translate-y-0 sm:scale-100"
leave="ease-in duration-200"
leave-from="opacity-100 translate-y-0 sm:scale-100"
leave-to="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95">
<DialogPanel
class="relative transform overflow-hidden rounded-lg bg-white px-4 pb-4 pt-5 text-left shadow-xl transition-all sm:my-8 sm:w-full sm:max-w-lg sm:p-6">
<div>
<div class="mx-auto flex h-12 w-12 items-center justify-center rounded-full bg-green-100">
<CheckIcon class="h-6 w-6 text-green-500" aria-hidden="true" />
<div
class="mx-auto flex h-12 w-12 items-center justify-center rounded-full bg-green-100">
<CheckIcon class="h-6 w-6 text-green-500" aria-hidden="true"/>
</div>

<div class="mt-3 text-center sm:mt-5">
<DialogTitle as="h3" class="text-base font-semibold leading-6 text-gray-900">
<DialogTitle as="h3"
class="text-base font-semibold leading-6 text-gray-900">
{{ title }}
</DialogTitle>
<div class="mt-2">
Expand All @@ -36,7 +46,9 @@
</div>
<div class="mt-5 sm:mt-6 sm:grid sm:grid-flow-row-dense sm:grid-cols-2 sm:gap-3">

<button type="button" class="mt-3 inline-flex w-full justify-center rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50 sm:col-start-1 sm:mt-0" @click="open = false">
<button type="button"
class="mt-3 inline-flex w-full justify-center rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50 sm:col-start-1 sm:mt-0"
@click="open = false">
{{ cancelModalText }}
</button>

Expand All @@ -59,46 +71,112 @@
</template>

<script setup>
/** Import from vue. */
import { ref } from 'vue';
/** Import from vue. */
import {ref} from 'vue';
/** Import from inertia */
import { useForm } from '@inertiajs/vue3';
/** Import from inertia */
import {useForm} from '@inertiajs/vue3';
/** Import plugins. */;
import { Dialog, DialogPanel, DialogTitle, TransitionChild, TransitionRoot } from '@headlessui/vue';
import { CheckIcon } from '@heroicons/vue/24/outline';
/** Import plugins. */
;
import {Dialog, DialogPanel, DialogTitle, TransitionChild, TransitionRoot} from '@headlessui/vue';
import {CheckIcon} from '@heroicons/vue/24/outline';
/** Component props. */
const props = defineProps({
triggerModalText: String,
cancelModalText: String,
actionModalText: String,
triggerModalClasses: String,
title: String,
body: String,
actionRoute: String,
id: [String, Number],
data: [Object, Array]
});
/** Component props. */
const props = defineProps({
triggerModalText: String,
cancelModalText: String,
actionModalText: String,
triggerModalClasses: String,
title: String,
body: String,
actionRoute: String,
actionType: {
String,
default: 'delete'
},
id: [String, Number],
data: [Object, Array]
});
/** Local state. */
const open = ref(false);
console.log(props.actionType)
/** Local state. */
const open = ref(false);
/** Delete action. */
const action = () => {
/** Initialize inertia from Object. */
/** Delete action. */
const action = () => {
/** Initialize inertia from Object. */
if (props.actionType === 'approve') {
const form = useForm({});
form.delete(props.actionRoute, {
onSuccess: () => {
open.value = false
},
onError: () => {
open.value = true
},
onFinish: () => {
open.value = false
}
approveForm(form)
return;
}
if (props.actionType==='reject'){
const form = useForm({});
rejectForm(form)
return;
}
if (props.actionType === 'deleteVolunteer') {
const form = useForm({
project_ids: []
});
};
form.project_ids = props.data.map(project => project.id);
detachVolunteerFromProjects(form)
return;
}
const form = useForm({});
form.delete(props.actionRoute, {
onSuccess: () => {
open.value = false
},
onError: () => {
open.value = true
},
onFinish: () => {
open.value = false
}
});
};
const approveForm= (form)=>{
form.post(props.actionRoute, {
onSuccess: () => {
open.value = false
},
onError: () => {
open.value = true
},
onFinish: () => {
open.value = false
}
});
}
const rejectForm= (form)=>{
form.post(props.actionRoute, {
onSuccess: () => {
open.value = false
},
onError: () => {
open.value = true
},
onFinish: () => {
open.value = false
}
});
}
const detachVolunteerFromProjects=(form) =>{
form.post(props.actionRoute, {
onSuccess: () => {
open.value = false
},
onError: () => {
open.value = true
},
onFinish: () => {
open.value = false
}
});
}
</script>
27 changes: 16 additions & 11 deletions resources/js/Pages/AdminOng/Volunteers/Volunteers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@
:cancelModalText="$t('cancel')"
:actionModalText="$t('accept')"
:title="$t('confirm')"
:body="`${$t('confirm_accept_text')} ${person.user?.name}`"
actionRoute="route('admin.client.destroy', person.user.id)"
:body="`${$t('confirm_accept_text')} ${person.user?.name ? person.user.name : person.first_name+' '+person.last_name}`"
:actionRoute="route('admin.ong.volunteers.approve', person.id)"
:actionType="'approve'"
:data="volunteers.data"
/>
Expand All @@ -70,8 +71,10 @@
:cancelModalText="$t('cancel')"
:actionModalText="$t('reject')"
:title="$t('confirm')"
:body="`${$t('confirm_reject_text')} ${person.user?.name}`"
actionRoute="route('admin.client.destroy', person.user.id)"
:body="`${$t('confirm_reject_text')} ${person.user?.name ? person.user.name : person.first_name+' '+person.last_name}`"
:actionRoute="route('admin.ong.volunteers.reject', person.id)"
:actionType="'reject'"
:data="volunteers.data"
/>
</td >
Expand All @@ -82,20 +85,22 @@
:cancelModalText="$t('cancel')"
:actionModalText="$t('delete')"
:title="$t('confirm')"
:body="`${$t('confirm_delete_text')} ${person.user?.name}`"
actionRoute="route('admin.client.destroy', person.user.id)"
:data="volunteers.data"
:body="`${$t('confirm_delete_text')} ${person.user?.name ? person.user.name : person.first_name+' '+person.last_name}`"
:actionRoute="route('admin.ong.volunteers.delete', person.id)"
:actionType="'deleteVolunteer'"
:data="person.projects"
/>
</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>
<ModalAction
triggerModalClasses="block text-sm font-medium leadin-5 text-blue-500"
:triggerModalText="$t('delete')"
:triggerModalText="$t('reject')"
:cancelModalText="$t('cancel')"
:actionModalText="$t('delete')"
:actionModalText="$t('reject')"
:title="$t('confirm')"
:body="`${$t('confirm_delete_text')} ${person.user?.name} `"
actionRoute="route('admin.client.destroy', person.user.id)"
:body="`${$t('confirm_reject_text')} ${person.user?.name ? person.user.name : person.first_name+' '+person.last_name}`"
:actionRoute="route('admin.ong.volunteers.reject', person.id)"
:actionType="'reject'"
:data="volunteers.data"
/>
</td>
Expand Down
3 changes: 3 additions & 0 deletions routes/volunteers.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@

Route::prefix('ong')->middleware('auth')->group(function () {
Route::get('voluntari/{status?}', [\App\Http\Controllers\Ngo\VolunteerController::class, 'index'])->name('admin.ong.volunteers');;
Route::post('voluntari/approve/{id}', [\App\Http\Controllers\Ngo\VolunteerController::class, 'approve'])->name('admin.ong.volunteers.approve');;
Route::post('voluntari/reject/{id}', [\App\Http\Controllers\Ngo\VolunteerController::class, 'reject'])->name('admin.ong.volunteers.reject');;
Route::post('voluntari/delete/{id}', [\App\Http\Controllers\Ngo\VolunteerController::class, 'delete'])->name('admin.ong.volunteers.delete');;
});

0 comments on commit 5da562a

Please sign in to comment.