Update
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace Modules\Internal\Http\Controllers\Api;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use App\Models\Organization;
|
||||
use Illuminate\Contracts\Support\Renderable;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
@@ -110,11 +111,21 @@ class UserManagementController extends Controller
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public function list_organization(Request $request)
|
||||
{
|
||||
$query = Organization::where('type', 'hospital')->get();
|
||||
$data = [
|
||||
'data' => $query
|
||||
];
|
||||
return response()->json($data);
|
||||
}
|
||||
|
||||
public function store_access(Request $request){
|
||||
$user = User::create([
|
||||
'email' => $request->email,
|
||||
'username' => $request->username,
|
||||
'role_id' => $request->roles,
|
||||
'organization_id' => $request->organizations,
|
||||
'password' => Hash::make($request->password),
|
||||
]);
|
||||
|
||||
@@ -164,6 +175,7 @@ class UserManagementController extends Controller
|
||||
$userAccess->email = $request->email;
|
||||
$userAccess->username = $request->username;
|
||||
$userAccess->role_id = $request->roles;
|
||||
$userAccess->organization_id = $request->organizations;
|
||||
|
||||
if ($request->password){
|
||||
$userAccess->password = Hash::make($request->password);
|
||||
|
||||
@@ -394,6 +394,7 @@ Route::prefix('internal')->group(function () {
|
||||
Route::get('user/access/{id}', [UserManagementController::class, 'edit_access']);
|
||||
Route::put('user/access/{id}', [UserManagementController::class, 'update_access']);
|
||||
Route::get('role-list', [UserManagementController::class, 'list_role']);
|
||||
Route::get('organization-list', [UserManagementController::class, 'list_organization']);
|
||||
|
||||
// Navigation
|
||||
Route::get('navigations', [NavigationController::class, 'index']);
|
||||
|
||||
@@ -25,6 +25,7 @@ class User extends Authenticatable
|
||||
|
||||
protected $connection = 'mysql';
|
||||
protected $fillable = [
|
||||
'organization_id',
|
||||
'person_id',
|
||||
'name',
|
||||
'email',
|
||||
|
||||
@@ -134,6 +134,11 @@ export type Role = {
|
||||
permissions: number[]
|
||||
};
|
||||
|
||||
export type Organization = {
|
||||
id: number;
|
||||
name: string;
|
||||
};
|
||||
|
||||
export type Permisions = {
|
||||
name: string;
|
||||
guard_name: string;
|
||||
@@ -146,6 +151,7 @@ export type UserAccess = {
|
||||
email: string;
|
||||
person: Person;
|
||||
role: Role;
|
||||
organization_id: Organization;
|
||||
}
|
||||
|
||||
export type Person = {
|
||||
|
||||
@@ -6,6 +6,7 @@ import {useContext, useEffect, useMemo, useState } from 'react';
|
||||
import axios from '../../../utils/axios';
|
||||
import UserAccessForm from './Form';
|
||||
import { Role, UserAccess } from '../../../@types/user';
|
||||
import Organizations from "@/pages/Master/Hospitals/Index";
|
||||
|
||||
|
||||
|
||||
@@ -13,6 +14,7 @@ export default function UserAccessCreate() {
|
||||
const { id } = useParams();
|
||||
const [ currentUserAccess, setCurrentUserAccess ] = useState<UserAccess>();
|
||||
const [ roles, setRole ] = useState<any>();
|
||||
const [ organizations, setOrganization ] = useState<any>();
|
||||
|
||||
|
||||
const navigate = useNavigate();
|
||||
@@ -41,6 +43,16 @@ export default function UserAccessCreate() {
|
||||
}
|
||||
})
|
||||
|
||||
axios.get('/organization-list')
|
||||
.then((res)=> {
|
||||
setOrganization(res.data)
|
||||
})
|
||||
.catch((err) => {
|
||||
if (err.response.status === 404) {
|
||||
navigate('/404');
|
||||
}
|
||||
})
|
||||
|
||||
}, [id]);
|
||||
|
||||
|
||||
@@ -57,7 +69,7 @@ export default function UserAccessCreate() {
|
||||
]}
|
||||
/>
|
||||
|
||||
<UserAccessForm isEdit={isEdit} currentUserAccess={currentUserAccess} roles={roles}/>
|
||||
<UserAccessForm isEdit={isEdit} currentUserAccess={currentUserAccess} roles={roles} organizations={organizations}/>
|
||||
</Page>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as Yup from 'yup';
|
||||
import { LoadingButton } from "@mui/lab";
|
||||
import { Box, Card, Grid, Stack, Typography } from "@mui/material";
|
||||
import { Role, UserAccess } from "../../../@types/user";
|
||||
import { Role, UserAccess, Organization } from "../../../@types/user";
|
||||
import { FormProvider, RHFSelect, RHFSwitch, RHFTextField } from "../../../components/hook-form";
|
||||
import { useEffect, useMemo } from 'react';
|
||||
import { useForm } from 'react-hook-form';
|
||||
@@ -14,10 +14,11 @@ import palette from '@/theme/palette';
|
||||
type Props = {
|
||||
isEdit: boolean;
|
||||
currentUserAccess?: UserAccess;
|
||||
roles: Role
|
||||
roles: Role;
|
||||
organizations: Organization;
|
||||
};
|
||||
|
||||
export default function AccsessForm({ isEdit, currentUserAccess, roles }: Props) {
|
||||
export default function AccsessForm({ isEdit, currentUserAccess, roles, organizations }: Props) {
|
||||
|
||||
const { enqueueSnackbar } = useSnackbar();
|
||||
const navigate = useNavigate();
|
||||
@@ -34,6 +35,7 @@ export default function AccsessForm({ isEdit, currentUserAccess, roles }: Props)
|
||||
username: currentUserAccess?.username || '',
|
||||
email: currentUserAccess?.email || '',
|
||||
roles: currentUserAccess?.role?.id || [],
|
||||
organizations: currentUserAccess?.organization_id || [],
|
||||
password: '',
|
||||
}),
|
||||
[currentUserAccess]
|
||||
@@ -107,11 +109,20 @@ export default function AccsessForm({ isEdit, currentUserAccess, roles }: Props)
|
||||
value: item.id,
|
||||
label: item.name
|
||||
})) ?? [];
|
||||
|
||||
|
||||
if (optionsRoles.length > 0) {
|
||||
optionsRoles.unshift({ value: '', label: '' });
|
||||
}
|
||||
|
||||
const optionsOrganization = organizations?.data?.map(item => ({
|
||||
value: item.id,
|
||||
label: item.name
|
||||
})) ?? [];
|
||||
|
||||
if (optionsOrganization.length > 0) {
|
||||
optionsOrganization.unshift({ value: '', label: '' });
|
||||
}
|
||||
|
||||
return (
|
||||
<FormProvider methods={methods} onSubmit={handleSubmit(onSubmit)}>
|
||||
<Box sx={{ px: 2 }}>
|
||||
@@ -131,6 +142,13 @@ export default function AccsessForm({ isEdit, currentUserAccess, roles }: Props)
|
||||
</option>
|
||||
))}
|
||||
</RHFSelect>
|
||||
<RHFSelect name="organizations" label="organizations">
|
||||
{optionsOrganization.map((option, index) => (
|
||||
<option key={index} value={option.value}>
|
||||
{option.label}
|
||||
</option>
|
||||
))}
|
||||
</RHFSelect>
|
||||
|
||||
|
||||
<LoadingButton type="submit" variant="contained" size="large" fullWidth={true} loading={isSubmitting}>
|
||||
|
||||
Reference in New Issue
Block a user