first commit
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
<script setup lang="ts">
|
||||
import { useForm } from '@inertiajs/vue3';
|
||||
import Button from '@/components/ui/Button.vue';
|
||||
import Input from '@/components/ui/Input.vue';
|
||||
import Textarea from '@/components/ui/Textarea.vue';
|
||||
import { useTranslations } from '@/composables/useVanguard';
|
||||
import AppLayout from '@/layouts/AppLayout.vue';
|
||||
|
||||
interface Role {
|
||||
id: number;
|
||||
name: string;
|
||||
display_name: string | null;
|
||||
description: string | null;
|
||||
}
|
||||
|
||||
const props = defineProps<{ edit: boolean; role?: Role | null }>();
|
||||
|
||||
const { __ } = useTranslations();
|
||||
|
||||
const form = useForm({
|
||||
name: props.role?.name ?? '',
|
||||
display_name: props.role?.display_name ?? '',
|
||||
description: props.role?.description ?? '',
|
||||
});
|
||||
|
||||
function submit() {
|
||||
if (props.edit && props.role) {
|
||||
form.put(route('roles.update', props.role.id));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
form.post(route('roles.store'));
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppLayout
|
||||
:title="__('Roles')"
|
||||
:heading="edit && role ? role.name : __('Create New Role')"
|
||||
:breadcrumbs="[
|
||||
{ label: __('Roles'), href: route('roles.index') },
|
||||
{ label: edit ? __('Edit') : __('Create') },
|
||||
]"
|
||||
>
|
||||
<form @submit.prevent="submit">
|
||||
<div class="rounded-lg border border-slate-200 bg-white p-6 shadow-sm">
|
||||
<div class="grid grid-cols-1 gap-6 md:grid-cols-4">
|
||||
<div class="md:col-span-1">
|
||||
<h5 class="font-medium text-slate-800">{{ __('Role Details') }}</h5>
|
||||
<p class="text-slate-500">{{ __('A general role information.') }}</p>
|
||||
</div>
|
||||
|
||||
<div class="space-y-4 md:col-span-3">
|
||||
<div>
|
||||
<label for="name" class="mb-1 block text-slate-700">{{ __('Name') }}</label>
|
||||
<Input
|
||||
id="name"
|
||||
v-model="form.name"
|
||||
class="w-full"
|
||||
:placeholder="__('Role Name')"
|
||||
:invalid="Boolean(form.errors.name)"
|
||||
/>
|
||||
<small v-if="form.errors.name" class="text-red-600">{{ form.errors.name }}</small>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="display_name" class="mb-1 block text-slate-700">
|
||||
{{ __('Display Name') }}
|
||||
</label>
|
||||
<Input
|
||||
id="display_name"
|
||||
v-model="form.display_name"
|
||||
class="w-full"
|
||||
:placeholder="__('Display Name')"
|
||||
:invalid="Boolean(form.errors.display_name)"
|
||||
/>
|
||||
<small v-if="form.errors.display_name" class="text-red-600">
|
||||
{{ form.errors.display_name }}
|
||||
</small>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="description" class="mb-1 block text-slate-700">
|
||||
{{ __('Description') }}
|
||||
</label>
|
||||
<Textarea
|
||||
id="description"
|
||||
v-model="form.description"
|
||||
class="w-full"
|
||||
:rows="3"
|
||||
:invalid="Boolean(form.errors.description)"
|
||||
/>
|
||||
<small v-if="form.errors.description" class="text-red-600">
|
||||
{{ form.errors.description }}
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
type="submit"
|
||||
:label="edit ? __('Update Role') : __('Create Role')"
|
||||
class="mt-4"
|
||||
:loading="form.processing"
|
||||
/>
|
||||
</form>
|
||||
</AppLayout>
|
||||
</template>
|
||||
@@ -0,0 +1,100 @@
|
||||
<script setup lang="ts">
|
||||
import { Link } from '@inertiajs/vue3';
|
||||
import Button from '@/components/ui/Button.vue';
|
||||
import Tooltip from '@/components/ui/Tooltip.vue';
|
||||
import { useConfirmDelete } from '@/composables/useConfirmDelete';
|
||||
import { useTranslations } from '@/composables/useVanguard';
|
||||
import AppLayout from '@/layouts/AppLayout.vue';
|
||||
|
||||
interface Role {
|
||||
id: number;
|
||||
name: string;
|
||||
display_name: string | null;
|
||||
users_count: number;
|
||||
removable: boolean;
|
||||
editUrl: string;
|
||||
deleteUrl: string;
|
||||
}
|
||||
|
||||
defineProps<{ roles: Role[] }>();
|
||||
|
||||
const { __ } = useTranslations();
|
||||
const { confirmDelete } = useConfirmDelete();
|
||||
|
||||
function remove(role: Role) {
|
||||
confirmDelete({
|
||||
url: role.deleteUrl,
|
||||
message: __('Are you sure that you want to delete this role?'),
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppLayout :title="__('Roles')" :heading="__('Roles')" :breadcrumbs="[{ label: __('Roles') }]">
|
||||
<div class="rounded-lg border border-slate-200 bg-white p-6 shadow-sm">
|
||||
<div class="mb-4 flex justify-end border-b border-slate-100 pb-4">
|
||||
<Link :href="route('roles.create')">
|
||||
<Button :label="__('Add Role')" icon="fas fa-plus" rounded />
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
<div class="overflow-x-auto">
|
||||
<table class="w-full min-w-2xl text-left">
|
||||
<thead>
|
||||
<tr class="border-b border-slate-100">
|
||||
<th class="px-4 py-3 font-medium">{{ __('Name') }}</th>
|
||||
<th class="px-4 py-3 font-medium">{{ __('Display Name') }}</th>
|
||||
<th class="px-4 py-3 font-medium">
|
||||
{{ __('# of users with this role') }}
|
||||
</th>
|
||||
<th class="w-40 px-4 py-3 text-center font-medium">{{ __('Action') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<tr v-if="!roles.length">
|
||||
<td colspan="4" class="px-4 py-3">
|
||||
<em class="text-slate-500">{{ __('No records found.') }}</em>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr
|
||||
v-for="role in roles"
|
||||
:key="role.id"
|
||||
class="odd:bg-body border-b border-slate-50"
|
||||
>
|
||||
<td class="px-4 py-3">{{ role.name }}</td>
|
||||
<td class="px-4 py-3">{{ role.display_name }}</td>
|
||||
<td class="px-4 py-3">{{ role.users_count }}</td>
|
||||
|
||||
<td class="px-4 py-3 text-center">
|
||||
<Tooltip :text="__('Edit Role')">
|
||||
<Link :href="role.editUrl">
|
||||
<Button
|
||||
icon="fas fa-edit"
|
||||
text
|
||||
rounded
|
||||
severity="secondary"
|
||||
:aria-label="__('Edit Role')"
|
||||
/>
|
||||
</Link>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip v-if="role.removable" :text="__('Delete Role')">
|
||||
<Button
|
||||
icon="fas fa-trash"
|
||||
text
|
||||
rounded
|
||||
severity="secondary"
|
||||
:aria-label="__('Delete Role')"
|
||||
@click="remove(role)"
|
||||
/>
|
||||
</Tooltip>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</AppLayout>
|
||||
</template>
|
||||
Reference in New Issue
Block a user