add default setting

v1
Aji Kamaludin 10 months ago
parent 4c32170aa2
commit b7ce034122
No known key found for this signature in database
GPG Key ID: 19058F67F0083AD3

@ -48,7 +48,7 @@ class UserController extends Controller
{
$request->validate([
'name' => 'required|string|max:255',
'email' => 'required|email|unique:users,email,' . $user->id,
'email' => 'required|email|unique:users,email,'.$user->id,
'password' => 'nullable|string|max:255',
]);

@ -36,6 +36,7 @@ class HandleInertiaRequests extends Middleware
'flash' => [
'message' => fn () => $request->session()->get('message'),
],
'app_name' => env('APP_NAME', 'App Name'),
]);
}
}

@ -23,4 +23,4 @@ class HttpSecureAware
return $next($request);
}
}
}

@ -2,7 +2,9 @@
namespace Database\Seeders;
use App\Models\Setting;
use Illuminate\Database\Seeder;
use Illuminate\Support\Str;
class DummySeeder extends Seeder
{
@ -13,6 +15,10 @@ class DummySeeder extends Seeder
*/
public function run()
{
//
$settings = [
['id' => Str::ulid(), 'key' => 'app_name', 'value' => 'Customer Point', 'type' => 'text'],
];
Setting::insert($settings);
}
}

@ -30,6 +30,8 @@ class PermissionSeeder extends Seeder
['id' => Str::ulid(), 'label' => 'Update Role', 'name' => 'update-role'],
['id' => Str::ulid(), 'label' => 'View Role', 'name' => 'view-role'],
['id' => Str::ulid(), 'label' => 'Delete Role', 'name' => 'delete-role'],
['id' => Str::ulid(), 'label' => 'View Setting', 'name' => 'view-setting'],
];
foreach ($permissions as $permission) {

@ -1,7 +1,10 @@
import React from 'react';
import { usePage } from '@inertiajs/react'
import React from 'react'
export default function ApplicationLogo({ className }) {
return (
<h1 className={className}>App Name</h1>
);
const {
props: { app_name },
} = usePage()
return <h1 className={className}>{app_name}</h1>
}

@ -1,11 +1,31 @@
import React from "react";
import Input from "./Input";
import React from 'react'
import Input from './Input'
export default function FormInput({ type, name, onChange, value, label, className, error, autoComplete, autoFocus, placeholder, disabled, readOnly}) {
export default function FormInput({
type,
name,
onChange,
value,
label,
className,
error,
autoComplete,
autoFocus,
placeholder,
disabled,
readOnly,
}) {
const id = `${name}-${label}`
return (
<div className={className}>
<label htmlFor="first_name" className="block mb-2 text-sm font-medium text-gray-900 dark:text-white">{label}</label>
<label
htmlFor={id}
className="block mb-2 text-sm font-medium text-gray-900 dark:text-white"
>
{label}
</label>
<Input
id={id}
type={type}
name={name}
onChange={onChange}
@ -19,4 +39,4 @@ export default function FormInput({ type, name, onChange, value, label, classNam
/>
</div>
)
}
}

@ -1,24 +1,43 @@
import React from 'react'
export default function Input({ type = 'text', name, onChange, value, error = "", autoComplete = false, autoFocus = false, placeholder , className ,disabled, readOnly}) {
export default function Input({
type = 'text',
name,
onChange,
value,
error = '',
autoComplete = false,
autoFocus = false,
placeholder,
className,
disabled,
readOnly,
id,
}) {
return (
<>
<input
<input
id={id}
type={type}
className={`mb-2 bg-gray-50 border text-gray-900 text-sm rounded-lg block w-full p-2.5 dark:bg-gray-700 dark:placeholder-gray-400 dark:text-white ${error ? "border-red-500 dark:border-red-500 focus:ring-red-500 focus:border-red-500 dark:focus:ring-red-500 dark:focus:border-red-500" : "border-gray-300 dark:border-gray-600 focus:ring-blue-500 focus:border-blue-500 dark:focus:ring-blue-500 dark:focus:border-blue-500"} ${className}`}
onChange={onChange}
className={`mb-2 bg-gray-50 border text-gray-900 text-sm rounded-lg block w-full p-2.5 dark:bg-gray-700 dark:placeholder-gray-400 dark:text-white ${
error
? 'border-red-500 dark:border-red-500 focus:ring-red-500 focus:border-red-500 dark:focus:ring-red-500 dark:focus:border-red-500'
: 'border-gray-300 dark:border-gray-600 focus:ring-blue-500 focus:border-blue-500 dark:focus:ring-blue-500 dark:focus:border-blue-500'
} ${className}`}
onChange={onChange}
name={name}
value={value}
autoComplete={autoComplete ? "on" : "off"}
autoComplete={autoComplete ? 'on' : 'off'}
autoFocus={autoFocus}
placeholder={placeholder}
disabled={disabled}
readOnly={readOnly}
/>
{error && (
<p className="mb-2 text-sm text-red-600 dark:text-red-500">{error}</p>
<p className="mb-2 text-sm text-red-600 dark:text-red-500">
{error}
</p>
)}
</>
)
}
}

@ -1,21 +1,21 @@
import React from 'react';
import { router } from '@inertiajs/react';
import { Sidebar } from 'flowbite-react';
import { HiLogout } from 'react-icons/hi';
import { filterOpenMenu } from './helpers';
import routes from './routes';
import { formatDate } from '@/utils';
import React from 'react'
import { router } from '@inertiajs/react'
import { Sidebar } from 'flowbite-react'
import { HiLogout } from 'react-icons/hi'
import { filterOpenMenu } from './helpers'
import routes from './routes'
import { formatDate } from '@/utils'
export default function SidebarNav({ user }) {
const menus = routes.filter(item => {
const menus = routes.filter((item) => {
item.open = false
if (!item.show) {
return null
}
if (+user.is_superadmin === 1) {
if (user.role === null) {
return filterOpenMenu(user, item)
}
if(user.role.permissions.find(p => p.name === item.permission)) {
if (user.role.permissions.find((p) => p.name === item.permission)) {
return item
}
@ -26,33 +26,36 @@ export default function SidebarNav({ user }) {
<Sidebar aria-label="Sidebar with multi-level dropdown example">
<Sidebar.Items>
<Sidebar.ItemGroup>
{menus.map(item => (
{menus.map((item) => (
<div key={item.name}>
{item.items === undefined ? (
<Sidebar.Item
onClick={() => router.visit(item.route)}
icon={item.icon}
active={route().current(item.active)}
>
{item.name}
</Sidebar.Item>
<Sidebar.Item
onClick={() => router.visit(item.route)}
icon={item.icon}
active={route().current(item.active)}
>
{item.name}
</Sidebar.Item>
) : (
<Sidebar.Collapse
icon={item.icon}
label={item.name}
open={item.open}
>
{item.items.map(item => (
<Sidebar.Item
{item.items.map((item) => (
<Sidebar.Item
key={item.name}
onClick={() => router.visit(item.route)}
onClick={() =>
router.visit(item.route)
}
icon={item.icon}
active={route().current(item.active)}
active={route().current(
item.active
)}
>
{item.name}
</Sidebar.Item>
))}
</Sidebar.Collapse>
)}
</div>
@ -64,10 +67,10 @@ export default function SidebarNav({ user }) {
Logout
</Sidebar.Item>
</Sidebar.ItemGroup>
<p className='text-sm font-light text-gray-900 dark:text-gray-100 text-center bottom-4 left-4 pt-10'>
App Name &copy; {(new Date()).getFullYear()}
<p className="text-sm font-light text-gray-900 dark:text-gray-100 text-center bottom-4 left-4 pt-10">
App Name &copy; {new Date().getFullYear()}
</p>
</Sidebar.Items>
</Sidebar>
)
}
}

@ -1,21 +1,25 @@
export const filterOpenMenu = (user, item) => {
const isAdmin = +user.is_superadmin === 1
const isAdmin = user.role === null
if ('items' in item) {
let items = []
if (isAdmin) {
items = item.items
} else {
items = item.items.filter(item => user.role.permissions.find(p => p.name === item.permission) ? item : null)
items = item.items.filter((item) =>
user.role.permissions.find((p) => p.name === item.permission)
? item
: null
)
}
if (items.length > 0) {
let activeItem = items.map(item => route().current(item.active))
let activeItem = items.map((item) => route().current(item.active))
item.open = activeItem.includes(true)
item.items = items.filter(item => item.show ? item : null)
item.items = items.filter((item) => (item.show ? item : null))
return item
}
}
if (isAdmin) {
return item
}
}
}

@ -18,39 +18,47 @@ import {
HiHome,
HiInboxIn,
HiOutlineCash,
HiOutlineTable
} from "react-icons/hi";
HiOutlineTable,
} from 'react-icons/hi'
export default [
{
name: "Dashboard",
name: 'Dashboard',
show: true,
icon: HiChartPie,
route: route("dashboard"),
active: "dashboard",
permission: "view-dashboard",
route: route('dashboard'),
active: 'dashboard',
permission: 'view-dashboard',
},
{
name: "User",
name: 'User',
show: true,
icon: HiUser,
items: [
{
name: "Roles",
name: 'Roles',
show: true,
icon: HiUserGroup,
route: route("roles.index"),
active: "roles.*",
permission: "view-role",
route: route('roles.index'),
active: 'roles.*',
permission: 'view-role',
},
{
name: "Users",
name: 'Users',
show: true,
icon: HiUsers,
route: route("user.index"),
active: "user.index",
permission: "view-user",
route: route('user.index'),
active: 'user.index',
permission: 'view-user',
},
],
},
];
{
name: 'Setting',
show: true,
icon: HiChartPie,
route: route('setting.index'),
active: 'setting.index',
permission: 'view-setting',
},
]

@ -13,47 +13,47 @@ use Illuminate\Support\Facades\Route;
Route::middleware('guest')->group(function () {
Route::get('register', [RegisteredUserController::class, 'create'])
->name('register');
->name('register');
Route::post('register', [RegisteredUserController::class, 'store']);
Route::get('login', [AuthenticatedSessionController::class, 'create'])
->name('login');
->name('login');
Route::post('login', [AuthenticatedSessionController::class, 'store']);
Route::get('forgot-password', [PasswordResetLinkController::class, 'create'])
->name('password.request');
->name('password.request');
Route::post('forgot-password', [PasswordResetLinkController::class, 'store'])
->name('password.email');
->name('password.email');
Route::get('reset-password/{token}', [NewPasswordController::class, 'create'])
->name('password.reset');
->name('password.reset');
Route::post('reset-password', [NewPasswordController::class, 'store'])
->name('password.store');
->name('password.store');
});
Route::middleware('auth')->group(function () {
Route::get('verify-email', [EmailVerificationPromptController::class, '__invoke'])
->name('verification.notice');
->name('verification.notice');
Route::get('verify-email/{id}/{hash}', [VerifyEmailController::class, '__invoke'])
->middleware(['signed', 'throttle:6,1'])
->name('verification.verify');
->middleware(['signed', 'throttle:6,1'])
->name('verification.verify');
Route::post('email/verification-notification', [EmailVerificationNotificationController::class, 'store'])
->middleware('throttle:6,1')
->name('verification.send');
->middleware('throttle:6,1')
->name('verification.send');
Route::get('confirm-password', [ConfirmablePasswordController::class, 'show'])
->name('password.confirm');
->name('password.confirm');
Route::post('confirm-password', [ConfirmablePasswordController::class, 'store']);
Route::put('password', [PasswordController::class, 'update'])->name('password.update');
Route::post('logout', [AuthenticatedSessionController::class, 'destroy'])
->name('logout');
->name('logout');
});

Loading…
Cancel
Save