Files
sam-manage/resources/views/users/create.blade.php
hskwon 39ed2ac3e3 feat(user-modal): 사용자 정보 모달 및 컨텍스트 메뉴 확장
사용자 모달 기능:
- 사용자 정보 모달 팝업 (조회/삭제/수정)
- 권한 요약 정보 (Web/API 권한 카운트)
- 2x2 그리드 레이아웃 (테넌트, 역할, 부서, 권한)
- 테이블 행 클릭으로 모달 열기
- 권한 관리 링크 클릭 시 해당 사용자 자동 선택

컨텍스트 메뉴 확장:
- permission-analyze 페이지 사용자 이름에 컨텍스트 메뉴
- user-permissions 페이지 사용자 버튼에 컨텍스트 메뉴
- 사용자 모달 내 테넌트 칩에 컨텍스트 메뉴
- 헤더 테넌트 배지에 컨텍스트 메뉴
- 테넌트 메뉴에 "이 테넌트로 전환" 기능 추가
2025-11-27 20:05:27 +09:00

196 lines
9.9 KiB
PHP

@extends('layouts.app')
@section('title', '사용자 생성')
@section('content')
<div class="container mx-auto max-w-4xl">
<!-- 페이지 헤더 -->
<div class="flex justify-between items-center mb-6">
<h1 class="text-2xl font-bold text-gray-800">👥 사용자 생성</h1>
<a href="{{ route('users.index') }}" class="text-gray-600 hover:text-gray-800">
목록으로
</a>
</div>
<!-- 영역 -->
<div class="bg-white rounded-lg shadow-sm p-6">
<form id="userForm"
hx-post="/api/admin/users"
hx-headers='{"X-CSRF-TOKEN": "{{ csrf_token() }}"}'
hx-swap="none">
<!-- 기본 정보 -->
<div class="mb-8">
<h2 class="text-lg font-semibold text-gray-800 mb-4 pb-2 border-b">기본 정보</h2>
<div class="grid grid-cols-2 gap-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">
사용자 ID
</label>
<input type="text" name="user_id" maxlength="50"
placeholder="선택사항"
class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
<p class="text-xs text-gray-500 mt-1">비워두면 자동 생성됩니다.</p>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">
이름 <span class="text-red-500">*</span>
</label>
<input type="text" name="name" required maxlength="100"
placeholder="홍길동"
class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
</div>
</div>
<!-- 계정 정보 -->
<div class="mb-8">
<h2 class="text-lg font-semibold text-gray-800 mb-4 pb-2 border-b">계정 정보</h2>
<div class="grid grid-cols-2 gap-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">
이메일 <span class="text-red-500">*</span>
</label>
<input type="email" name="email" required maxlength="255"
placeholder="user@example.com"
class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">
연락처
</label>
<input type="text" name="phone" maxlength="20"
placeholder="010-1234-5678"
class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
</div>
</div>
<!-- 비밀번호 -->
<div class="mb-8">
<h2 class="text-lg font-semibold text-gray-800 mb-4 pb-2 border-b">비밀번호</h2>
<div class="grid grid-cols-2 gap-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">
비밀번호 <span class="text-red-500">*</span>
</label>
<input type="password" name="password" required minlength="8"
placeholder="최소 8자 이상"
class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
<p class="text-xs text-gray-500 mt-1">최소 8 이상 입력하세요.</p>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">
비밀번호 확인 <span class="text-red-500">*</span>
</label>
<input type="password" name="password_confirmation" required minlength="8"
placeholder="비밀번호 재입력"
class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
</div>
</div>
<!-- 역할 설정 -->
<div class="mb-8">
<h2 class="text-lg font-semibold text-gray-800 mb-4 pb-2 border-b">역할 설정</h2>
@if($roles->isNotEmpty())
<div class="grid grid-cols-2 md:grid-cols-3 gap-3">
@foreach($roles as $role)
<label class="flex items-center p-3 border border-gray-200 rounded-lg hover:bg-gray-50 cursor-pointer">
<input type="checkbox" name="role_ids[]" value="{{ $role->id }}"
{{ in_array($role->id, old('role_ids', [])) ? 'checked' : '' }}
class="h-4 w-4 text-blue-600 rounded focus:ring-2 focus:ring-blue-500">
<span class="ml-2 text-sm text-gray-700">{{ $role->name }}</span>
<span class="ml-1 px-1.5 py-0.5 text-xs rounded {{ $role->guard_name === 'web' ? 'bg-blue-100 text-blue-600' : 'bg-green-100 text-green-600' }}">{{ $role->guard_name }}</span>
</label>
@endforeach
</div>
@else
<p class="text-sm text-gray-500">선택 가능한 역할이 없습니다.</p>
@endif
</div>
<!-- 부서 설정 -->
<div class="mb-8">
<h2 class="text-lg font-semibold text-gray-800 mb-4 pb-2 border-b">부서 설정</h2>
@if($departments->isNotEmpty())
<div class="grid grid-cols-2 md:grid-cols-3 gap-3">
@foreach($departments as $department)
<label class="flex items-center p-3 border border-gray-200 rounded-lg hover:bg-gray-50 cursor-pointer">
<input type="checkbox" name="department_ids[]" value="{{ $department->id }}"
{{ in_array($department->id, old('department_ids', [])) ? 'checked' : '' }}
class="h-4 w-4 text-green-600 rounded focus:ring-2 focus:ring-green-500">
<span class="ml-2 text-sm text-gray-700">{{ $department->name }}</span>
</label>
@endforeach
</div>
<p class="text-xs text-gray-500 mt-2"> 번째로 선택한 부서가 부서로 설정됩니다.</p>
@else
<p class="text-sm text-gray-500">선택 가능한 부서가 없습니다.</p>
@endif
</div>
<!-- 계정 상태 -->
<div class="mb-8">
<h2 class="text-lg font-semibold text-gray-800 mb-4 pb-2 border-b">계정 상태</h2>
<div class="flex items-center gap-6">
<label class="flex items-center">
<input type="checkbox" name="is_active" value="1" checked
class="h-4 w-4 text-blue-600 rounded focus:ring-2 focus:ring-blue-500">
<span class="ml-2 text-sm text-gray-700">활성 상태</span>
</label>
<label class="flex items-center">
<input type="checkbox" name="is_super_admin" value="1"
class="h-4 w-4 text-red-600 rounded focus:ring-2 focus:ring-red-500">
<span class="ml-2 text-sm text-gray-700">슈퍼 관리자</span>
</label>
</div>
</div>
<!-- 버튼 영역 -->
<div class="flex justify-end gap-3">
<a href="{{ route('users.index') }}"
class="px-6 py-2 border border-gray-300 rounded-lg text-gray-700 hover:bg-gray-50 transition">
취소
</a>
<button type="submit"
class="px-6 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg transition">
생성
</button>
</div>
</form>
</div>
</div>
@endsection
@push('scripts')
<script src="https://unpkg.com/htmx.org@1.9.10"></script>
<script>
// HTMX 응답 처리
document.body.addEventListener('htmx:afterRequest', function(event) {
if (event.detail.target.id === 'userForm') {
const response = JSON.parse(event.detail.xhr.response);
if (response.success) {
alert(response.message);
window.location.href = response.redirect;
} else {
alert('오류: ' + (response.message || '사용자 생성에 실패했습니다.'));
}
}
});
// 에러 처리
document.body.addEventListener('htmx:responseError', function(event) {
if (event.detail.xhr.status === 422) {
const errors = JSON.parse(event.detail.xhr.response).errors;
let errorMsg = '입력 오류:\n';
for (let field in errors) {
errorMsg += '- ' + errors[field].join('\n') + '\n';
}
alert(errorMsg);
} else {
alert('서버 오류가 발생했습니다.');
}
});
</script>
@endpush