Skip to content

Commit

Permalink
Fix organization edit
Browse files Browse the repository at this point in the history
  • Loading branch information
gheorghelupu17 committed Jun 20, 2023
1 parent 3c81ce4 commit 80b5320
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 23 deletions.
5 changes: 4 additions & 1 deletion app/Http/Controllers/Auth/RegisteredUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
use App\Models\ActivityDomain;
use App\Models\Organization;
use App\Models\User;
use App\Notifications\Ngo\OrganizationCreated;
use App\Notifications\Admin\OrganizationCreated as OrganizationCreatedAdmin;
use App\Notifications\Ngo\OrganizationCreated;
use App\Providers\RouteServiceProvider;
use Illuminate\Auth\Events\Registered;
use Illuminate\Http\RedirectResponse;
Expand Down Expand Up @@ -70,6 +70,9 @@ public function store(RegistrationRequest $request): RedirectResponse
auth()->user()->notify(new OrganizationCreated($organization));
$adminUsers = User::whereRole(UserRole::bb_admin)->get();
Notification::send($adminUsers, new OrganizationCreatedAdmin($organization));
$user->organization_id = $organization->id;
return redirect(RouteServiceProvider::ONG);

}

return redirect(RouteServiceProvider::HOME);
Expand Down
16 changes: 14 additions & 2 deletions app/Http/Controllers/OrganizationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,20 @@ public function show(Organization $organization)
/**
* Show the form for editing the specified resource.
*/
public function edit(Organization $organization)
public function edit()
{
$organization = auth()->user()->organization;
$activityDomains = cache()->remember('activityDomains', 60 * 60 * 24, function () {
return \App\Models\ActivityDomain::get(['name', 'id']);
});
$counties = cache()->remember('counties', 60 * 60 * 24, function () {
return \App\Models\County::get(['name', 'id']);
});

return Inertia::render('AdminOng/Ong/EditOng', [
'organization' => $organization,
'activity_domains' => ActivityDomain::cases(),
'activity_domains' => $activityDomains,
'counties' => $counties,
]);
}

Expand All @@ -108,6 +117,9 @@ public function update(UpdateOrganizationRequest $request, Organization $organiz
try {
/** Get all request data. */
$modelData = $request->input();
if ($request->hasFile('activity_domains')) {
$organization->activityDomains()->sync($request->input('activity_domains'));
}

$organization->update($modelData);

Expand Down
2 changes: 2 additions & 0 deletions app/Models/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class Organization extends Model
'deleted_at' => 'datetime',
];

protected $with = ['counties', 'activityDomains'];

public function projects(): HasMany
{
return $this->hasMany(Project::class);
Expand Down
1 change: 0 additions & 1 deletion app/Notifications/Admin/OrganizationCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace App\Notifications\Admin;

use App\Models\Organization;
use App\Models\Project;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
Expand Down
1 change: 0 additions & 1 deletion app/Notifications/Ngo/OrganizationCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace App\Notifications\Ngo;

use App\Models\Organization;
use App\Models\Project;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
Expand Down
6 changes: 5 additions & 1 deletion app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Providers;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
Expand All @@ -21,6 +22,9 @@ public function register(): void
*/
public function boot(): void
{
//
tap($this->app->isLocal(), function (bool $shouldBeEnabled) {
Model::preventLazyLoading($shouldBeEnabled);
Model::preventAccessingMissingAttributes($shouldBeEnabled);
});
}
}
1 change: 1 addition & 0 deletions app/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class RouteServiceProvider extends ServiceProvider
* @var string
*/
public const HOME = '/dashboard';
public const ONG = '/ong/organizatie';

/**
* Define your route model bindings, pattern filters, and other route configuration.
Expand Down
31 changes: 15 additions & 16 deletions resources/js/Pages/AdminOng/Ong/EditOng.vue
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@
<!-- Edit activity domains -->
<div class="bg-gray-100 px-4 py-6 grid grid-cols-12">
<dt class="col-span-12 md:col-span-5 text-base font-medium leading-6 text-gray-700">{{ $t('organization_activity_label') }}</dt>
<dt class="col-span-12 md:col-span-6 text-base font-medium leading-6 text-gray-700">{{ form.activity_domains.join(', ') }}</dt>
<dt class="col-span-12 md:col-span-6 text-base font-medium leading-6 text-gray-700">{{ form.activity_domains.map(item=>item.name).join(', ') }}</dt>
<EditModal
@action="editField"
class="col-span-1 flex justify-end"
>
<Select
<MultiSelectObjectFilter
class="w-full xl:w-1/2"
:label="$t('organization_activity_label')"
:options="activity_domains"
Expand Down Expand Up @@ -241,7 +241,7 @@
<!-- Edit organizaton email -->
<div class="bg-white px-4 py-6 grid grid-cols-12">
<dt class="col-span-12 md:col-span-5 text-base font-medium leading-6 text-gray-700">{{ $t('organization_email_label') }}</dt>
<dt class="col-span-12 md:col-span-6 text-base font-medium leading-6 text-gray-700">{{ form.email }}</dt>
<dt class="col-span-12 md:col-span-6 text-base font-medium leading-6 text-gray-700">{{ form.contact_email }}</dt>
<EditModal
@action="editField"
class="col-span-1 flex justify-end"
Expand All @@ -262,7 +262,7 @@
<!-- Edit organizaton phone -->
<div class="bg-gray-100 px-4 py-6 grid grid-cols-12">
<dt class="col-span-12 md:col-span-5 text-base font-medium leading-6 text-gray-700">{{ $t('organization_phone_label') }}</dt>
<dt class="col-span-12 md:col-span-6 text-base font-medium leading-6 text-gray-700">{{ form.phone }}</dt>
<dt class="col-span-12 md:col-span-6 text-base font-medium leading-6 text-gray-700">{{ form.contact_phone }}</dt>
<EditModal
@action="editField"
class="col-span-1 flex justify-end"
Expand Down Expand Up @@ -304,26 +304,19 @@
<!-- Edit organizaton address -->
<div class="bg-gray-100 px-4 py-6 grid grid-cols-12">
<dt class="col-span-12 md:col-span-5 text-base font-medium leading-6 text-gray-700">{{ $t('organization_address_label') }}</dt>
<dt class="col-span-12 md:col-span-6 text-base font-medium leading-6 text-gray-700">{{ form.street_address }}, {{ form.city.name }}, {{ form.county.name }}</dt>
<dt class="col-span-12 md:col-span-6 text-base font-medium leading-6 text-gray-700">{{ form.street_address }}, {{ form.counties.map(item=>item.name).join(', ')}} </dt>
<EditModal
@action="editField"
class="col-span-1 flex justify-end"
>
<div class="flex flex-col lg:flex-row gap-4">
<Select
class="w-full"
:label="$t('city_label')"
:options="activity_domains"
v-model="form.city"
:error="form.errors.city"
/>

<Select
<MultiSelectObjectFilter
class="w-full"
:label="$t('county_label')"
:options="activity_domains"
v-model="form.county"
:error="form.errors.county"
:options="counties"
v-model="form.counties"
:error="form.errors.counties"
/>
</div>

Expand Down Expand Up @@ -411,16 +404,22 @@
import Checkbox from '@/Components/form/Checkbox.vue';
import FileInput from '@/Components/form/FileInput.vue';
import ModalAction from '@/Components/modals/ModalAction.vue';
import MultiSelectObjectFilter from "@/Components/filters/MultiSelectObjectFilter.vue";
import {onMounted} from "vue";
/** Page props. */
const props = defineProps({
organization: Object,
activity_domains: Array,
counties: Array,
flash: Object
});
/** Initialize inertia from Object. */
const form = useForm({ ...props.organization });
onMounted(() => {
console.log(form);
})
const editField = () => {
form.put(route('admin.ong.update', form.id), {
Expand Down
2 changes: 1 addition & 1 deletion routes/organizations.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

/* Admin Ong routes. */
Route::prefix('ong')->middleware('auth')->group(function () {
Route::get('organizatie/{organization}', [OrganizationController::class, 'edit'])->name('admin.ong.edit');
Route::get('organizatie', [OrganizationController::class, 'edit'])->name('admin.ong.edit');
Route::put('organizatie/update/{organization}', [OrganizationController::class, 'update'])->name('admin.ong.update');
});

0 comments on commit 80b5320

Please sign in to comment.