Files
sam-manage/resources/views/users/index.blade.php
권혁성 9af64d7368 feat: [users] SAM접속 기능 개선 - 도메인 매핑 및 텍스트 변경
- LoginToken: APP_ENV 기반 도메인 매핑 (local→dev.*, production→stage.sam.it.kr)
- DEV접속 → SAM접속 텍스트 변경
- 사용자 테이블: 이메일 컬럼 제거, 이름 아래 이메일 표시, 뱃지 버튼 UI

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 01:18:05 +09:00

246 lines
11 KiB
PHP

@extends('layouts.app')
@section('title', '사용자 관리')
@section('content')
<!-- 페이지 헤더 -->
<div class="flex flex-col sm:flex-row sm:justify-between sm:items-center gap-4 mb-6">
<h1 class="text-2xl font-bold text-gray-800">사용자 관리</h1>
<div class="flex flex-wrap items-center gap-2 sm:gap-3">
<!-- 일괄 삭제 -->
<button onclick="bulkDelete()" id="bulkDeleteBtn"
class="bg-red-600 hover:bg-red-700 text-white px-4 py-2 rounded-lg transition flex items-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed"
disabled>
선택 삭제 (<span id="deleteCount">0</span>)
</button>
<!-- 일괄 복원 -->
<button onclick="bulkRestore()" id="bulkRestoreBtn"
class="bg-green-600 hover:bg-green-700 text-white px-4 py-2 rounded-lg transition flex items-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed"
disabled>
선택 복원 (<span id="restoreCount">0</span>)
</button>
@if(auth()->user()?->is_super_admin)
<!-- 일괄 영구삭제 (슈퍼관리자) -->
<button onclick="bulkForceDelete()" id="bulkForceDeleteBtn"
class="bg-gray-800 hover:bg-gray-900 text-white px-4 py-2 rounded-lg transition flex items-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed"
disabled>
선택 영구삭제 (<span id="forceDeleteCount">0</span>)
</button>
@endif
<a href="{{ route('users.create') }}" class="bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg transition text-center">
+ 사용자
</a>
</div>
</div>
<!-- 필터 영역 -->
<x-filter-collapsible id="filterForm">
<form id="filterForm" class="flex flex-wrap gap-2 sm:gap-4">
<!-- 검색 -->
<div class="flex-1 min-w-0 w-full sm:w-auto">
<input type="text"
name="search"
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 class="w-full sm:w-40">
<select name="employee_status" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
<option value="">전체</option>
<option value="active">재직</option>
<option value="leave">휴직</option>
<option value="resigned">퇴직</option>
</select>
</div>
<!-- 활성 상태 필터 -->
<div class="w-full sm:w-40">
<select name="is_active" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
<option value="">전체 활성</option>
<option value="1">활성</option>
<option value="0">비활성</option>
</select>
</div>
<!-- 검색 버튼 -->
<button type="submit" class="bg-gray-600 hover:bg-gray-700 text-white px-6 py-2 rounded-lg transition w-full sm:w-auto">
검색
</button>
</form>
</x-filter-collapsible>
<!-- 테이블 영역 (HTMX로 로드) -->
<div id="user-table"
hx-get="/api/admin/users?per_page=100"
hx-trigger="load, filterSubmit from:body"
hx-include="#filterForm"
hx-headers='{"X-CSRF-TOKEN": "{{ csrf_token() }}"}'
class="bg-white rounded-lg shadow-sm overflow-hidden">
<!-- 로딩 스피너 -->
<div class="flex justify-center items-center p-12">
<div class="animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600"></div>
</div>
</div>
@endsection
@push('scripts')
<script src="https://unpkg.com/htmx.org@1.9.10"></script>
<script>
// 폼 제출 시 HTMX 이벤트 트리거
document.getElementById('filterForm').addEventListener('submit', function(e) {
e.preventDefault();
htmx.trigger('#user-table', 'filterSubmit');
});
// HTMX 응답 후 필요한 초기화 처리
document.body.addEventListener('htmx:afterSwap', function(event) {
if (event.detail.target.id === 'user-table') {
// 필요시 테이블 로드 후 초기화 작업
}
});
// 삭제 확인
window.confirmDelete = function(id, name) {
showDeleteConfirm(name, () => {
htmx.ajax('DELETE', `/api/admin/users/${id}`, {
target: '#user-table',
swap: 'none',
headers: {
'X-CSRF-TOKEN': '{{ csrf_token() }}'
}
}).then(() => {
htmx.trigger('#user-table', 'filterSubmit');
});
});
};
// 복원 확인
window.confirmRestore = function(id, name) {
showConfirm(`"${name}" 사용자를 복원하시겠습니까?`, () => {
htmx.ajax('POST', `/api/admin/users/${id}/restore`, {
target: '#user-table',
swap: 'none',
headers: {
'X-CSRF-TOKEN': '{{ csrf_token() }}'
}
}).then(() => {
htmx.trigger('#user-table', 'filterSubmit');
});
}, { title: '복원 확인', icon: 'question' });
};
// 영구삭제 확인
window.confirmForceDelete = function(id, name) {
showPermanentDeleteConfirm(name, () => {
htmx.ajax('DELETE', `/api/admin/users/${id}/force`, {
target: '#user-table',
swap: 'none',
headers: {
'X-CSRF-TOKEN': '{{ csrf_token() }}'
}
}).then(() => {
htmx.trigger('#user-table', 'filterSubmit');
});
});
};
// SAM 사이트 접속 (자동 로그인)
window.openDevSite = function(id, name) {
showConfirm(`"${name}" 사용자로 SAM 사이트에 접속하시겠습니까?`, () => {
fetch(`/api/admin/users/${id}/login-token`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': '{{ csrf_token() }}'
}
})
.then(response => response.json())
.then(data => {
if (data.success && data.data?.url) {
window.open(data.data.url, '_blank');
} else {
showAlert(data.message || 'SAM 접속 토큰 생성에 실패했습니다.', 'error');
}
})
.catch(error => {
console.error('SAM 접속 오류:', error);
showAlert('SAM 접속 중 오류가 발생했습니다.', 'error');
});
}, { title: 'SAM 사이트 접속', icon: 'question' });
};
// ===== 일괄 작업 =====
window.toggleSelectAll = function(headerCheckbox) {
document.querySelectorAll('.bulk-checkbox').forEach(cb => cb.checked = headerCheckbox.checked);
updateBulkButtonState();
};
window.updateBulkButtonState = function() {
const checked = document.querySelectorAll('.bulk-checkbox:checked');
let activeCount = 0, deletedCount = 0;
checked.forEach(cb => {
if (cb.dataset.deleted === '1') { deletedCount++; } else { activeCount++; }
});
const deleteBtn = document.getElementById('bulkDeleteBtn');
const restoreBtn = document.getElementById('bulkRestoreBtn');
const forceDeleteBtn = document.getElementById('bulkForceDeleteBtn');
if (deleteBtn) { document.getElementById('deleteCount').textContent = activeCount; deleteBtn.disabled = activeCount === 0; }
if (restoreBtn) { document.getElementById('restoreCount').textContent = deletedCount; restoreBtn.disabled = deletedCount === 0; }
if (forceDeleteBtn) { document.getElementById('forceDeleteCount').textContent = deletedCount; forceDeleteBtn.disabled = deletedCount === 0; }
};
window.bulkDelete = function() {
const ids = Array.from(document.querySelectorAll('.bulk-checkbox:checked'))
.filter(cb => cb.dataset.deleted !== '1').map(cb => parseInt(cb.value));
if (ids.length === 0) { showToast('삭제할 사용자를 선택해주세요.', 'warning'); return; }
showDeleteConfirm(`${ids.length}명 사용자`, () => {
fetch('/api/admin/users/bulk-delete', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': '{{ csrf_token() }}', 'Accept': 'application/json' },
body: JSON.stringify({ ids })
}).then(r => r.json()).then(data => {
showToast(data.message || '삭제 완료', data.success ? 'success' : 'error');
htmx.trigger('#user-table', 'filterSubmit');
}).catch(() => showToast('삭제 중 오류 발생', 'error'));
});
};
window.bulkRestore = function() {
const ids = Array.from(document.querySelectorAll('.bulk-checkbox:checked'))
.filter(cb => cb.dataset.deleted === '1').map(cb => parseInt(cb.value));
if (ids.length === 0) { showToast('복원할 사용자를 선택해주세요.', 'warning'); return; }
showConfirm(`선택한 ${ids.length}명의 사용자를 복원하시겠습니까?`, () => {
fetch('/api/admin/users/bulk-restore', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': '{{ csrf_token() }}', 'Accept': 'application/json' },
body: JSON.stringify({ ids })
}).then(r => r.json()).then(data => {
showToast(data.message || '복원 완료', data.success ? 'success' : 'error');
htmx.trigger('#user-table', 'filterSubmit');
}).catch(() => showToast('복원 중 오류 발생', 'error'));
}, { title: '사용자 복원', icon: 'question' });
};
window.bulkForceDelete = function() {
const ids = Array.from(document.querySelectorAll('.bulk-checkbox:checked'))
.filter(cb => cb.dataset.deleted === '1').map(cb => parseInt(cb.value));
if (ids.length === 0) { showToast('영구삭제할 사용자를 선택해주세요.', 'warning'); return; }
showPermanentDeleteConfirm(`${ids.length}명 사용자`, () => {
fetch('/api/admin/users/bulk-force-delete', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': '{{ csrf_token() }}', 'Accept': 'application/json' },
body: JSON.stringify({ ids })
}).then(r => r.json()).then(data => {
showToast(data.message || '영구삭제 완료', data.success ? 'success' : 'error');
htmx.trigger('#user-table', 'filterSubmit');
}).catch(() => showToast('영구삭제 중 오류 발생', 'error'));
});
};
</script>
@endpush