Skip to content

Commit

Permalink
Added scaffold for edit page
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcage committed Nov 17, 2023
1 parent 1b47265 commit 5f70bab
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 21 deletions.
3 changes: 3 additions & 0 deletions app/Http/Resources/CommunityVolunteers/CommunityVolunteer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Models\CommunityVolunteers\Responsibility;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Storage;

/**
Expand Down Expand Up @@ -58,6 +59,8 @@ public function toArray($request): array
'url' => $request->user()->can('view', $this->resource)
? route('cmtyvol.show', $this)
: null,
'can_update' => $request->user()->can('update', $this->resource),
'can_delete' => $request->user()->can('delete', $this->resource),
];
}
}
94 changes: 94 additions & 0 deletions resources/js/pages/cmtyvol/CommunityVolunteersEditPage.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<template>
<b-container v-if="cmtyvol">
{{ cmtyvol }}
<!-- <WalletForm
:wallet="cmtyvol"
:title="$t('Edit community volunteer')"
:disabled="isBusy"
@submit="handleUpdate"
@cancel="handleCancel"
@delete="handleDelete"
/> -->
<p class="text-right">
<small>
{{ $t("Created") }}:
{{ cmtyvol.created_at | dateTimeFormat }} </small
><br />
<small>
{{ $t("Last updated") }}:
{{ cmtyvol.updated_at | dateTimeFormat }}
</small>
</p>
</b-container>
<b-container v-else>
{{ $t("Loading...") }}
</b-container>
</template>

<script>
import { showSnackbar } from "@/utils";
import cmtyvolApi from '@/api/cmtyvol/cmtyvol'
// import WalletForm from "@/components/accounting/WalletForm.vue";
export default {
title() {
return this.$t("Edit community volunteer");
},
components: {
// WalletForm
},
props: {
id: {
required: true
}
},
data() {
return {
cmtyvol: null,
isBusy: false
};
},
watch: {
$route() {
this.fetchData();
}
},
async created() {
this.fetchData();
},
methods: {
async fetchData() {
try {
let data = await cmtyvolApi.find(this.id);
this.cmtyvol = data.data;
} catch (err) {
alert(err);
}
},
async handleUpdate(formData) {
this.isBusy = true;
try {
await cmtyvolApi.update(this.id, formData);
showSnackbar(this.$t("Community volunteer updated."));
this.$router.push({ name: "cmtyvol.overview" });
} catch (err) {
alert(err);
}
this.isBusy = false;
},
async handleDelete() {
this.isBusy = true;
try {
await cmtyvolApi.delete(this.id);
showSnackbar(this.$t("Community volunteer deleted."));
this.$router.push({ name: "cmtyvol.overview" });
} catch (err) {
alert(err);
}
this.isBusy = false;
},
handleCancel() {
this.$router.push({ name: "cmtyvol.overview" });
}
}
};
</script>
39 changes: 18 additions & 21 deletions resources/js/pages/cmtyvol/CommunityVolunteersShowPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ import PhoneLink from "@/components/common/PhoneLink.vue";
import EmailLink from "@/components/common/EmailLink.vue";
import PageHeader from "@/components/layout/PageHeader.vue";
export default {
title() {
return this.$t("Community Volunteer");
},
components: {
CmtyvolComments,
EmailLink,
Expand Down Expand Up @@ -97,30 +100,24 @@ export default {
title: this.$t('Occupation'),
},
],
pageHeaderButtons: [
// {
// to: {
// name: "fundraising.donors.edit",
// params: { id: this.id }
// },
// variant: "primary",
// icon: "pencil-alt",
// text: this.$t("Edit"),
// show: this.can("manage-fundraising-entities")
// },
// {
// href: this.route(
// "cmtyvol.edit",
// this.id
// ),
// icon: "pencil-alt",
// text: this.$t("Edit"),
// show: this.can("view-fundraising-entities")
// },
],
}
},
computed: {
pageHeaderButtons() {
console.log(this.cmtyvol.can_update)
return [
{
to: {
name: "cmtyvol.edit",
params: { id: this.id }
},
variant: "primary",
icon: "pencil-alt",
text: this.$t("Edit"),
show: this.cmtyvol.can_update
},
]
},
fields() {
if (!this.cmtyvol) {
return []
Expand Down
29 changes: 29 additions & 0 deletions resources/js/router/cmtyvol.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,33 @@ export default [
}
}
},
{
path: "/cmtyvol/:id/edit",
name: "cmtyvol.edit",
components: {
default: () => import("@/pages/cmtyvol/CommunityVolunteersEditPage.vue"),
breadcrumbs: BreadcrumbsNav,
},
props: {
default: true,
breadcrumbs: route => ({
items: [
{
text: i18n.t('Community Volunteers'),
to: { name: "cmtyvol.overview" }
},
{
text: i18n.t('Community Volunteer'),
to: {
name: "cmtyvol.show",
params: { id: route.params.id }
},
},
{
text: i18n.t('Edit community volunteer'),
}
]
})
}
},
];

0 comments on commit 5f70bab

Please sign in to comment.