38499-vm/frontend/src/pages/users/users-view.tsx
2026-02-17 22:36:06 +00:00

1355 lines
49 KiB
TypeScript

import React, { ReactElement, useEffect } from 'react';
import Head from 'next/head'
import DatePicker from "react-datepicker";
import "react-datepicker/dist/react-datepicker.css";
import dayjs from "dayjs";
import {useAppDispatch, useAppSelector} from "../../stores/hooks";
import {useRouter} from "next/router";
import { fetch } from '../../stores/users/usersSlice'
import {saveFile} from "../../helpers/fileSaver";
import dataFormatter from '../../helpers/dataFormatter';
import ImageField from "../../components/ImageField";
import LayoutAuthenticated from "../../layouts/Authenticated";
import {getPageTitle} from "../../config";
import SectionTitleLineWithButton from "../../components/SectionTitleLineWithButton";
import SectionMain from "../../components/SectionMain";
import CardBox from "../../components/CardBox";
import BaseButton from "../../components/BaseButton";
import BaseDivider from "../../components/BaseDivider";
import {mdiChartTimelineVariant} from "@mdi/js";
import {SwitchField} from "../../components/SwitchField";
import FormField from "../../components/FormField";
import LoginHistoryTable from "../../components/Users/LoginHistoryTable";
import { leaveTypeLabels } from '../../components/Time_off_requests/configureTime_off_requestsCols';
const UsersView = () => {
const router = useRouter()
const dispatch = useAppDispatch()
const { users } = useAppSelector((state) => state.users)
const { id } = router.query;
function removeLastCharacter(str) {
console.log(str,`str`)
return str.slice(0, -1);
}
useEffect(() => {
dispatch(fetch({ id }));
}, [dispatch, id]);
return (
<>
<Head>
<title>{getPageTitle('View users')}</title>
</Head>
<SectionMain>
<SectionTitleLineWithButton icon={mdiChartTimelineVariant} title={removeLastCharacter('View users')} main>
<BaseButton
color='info'
label='Edit'
href={`/users/users-edit/?id=${id}`}
/>
</SectionTitleLineWithButton>
<CardBox>
<div className={'mb-4'}>
<p className={'block font-bold mb-2'}>First Name</p>
<p>{users?.firstName}</p>
</div>
<div className={'mb-4'}>
<p className={'block font-bold mb-2'}>Last Name</p>
<p>{users?.lastName}</p>
</div>
<div className={'mb-4'}>
<p className={'block font-bold mb-2'}>Phone Number</p>
<p>{users?.phoneNumber}</p>
</div>
<div className={'mb-4'}>
<p className={'block font-bold mb-2'}>E-Mail</p>
<p>{users?.email}</p>
</div>
<FormField label='Disabled'>
<SwitchField
field={{name: 'disabled', value: users?.disabled}}
form={{setFieldValue: () => null}}
disabled
/>
</FormField>
<div className={'mb-4'}>
<p className={'block font-bold mb-2'}>Avatar</p>
{users?.avatar?.length
? (
<ImageField
name={'avatar'}
image={users?.avatar}
className='w-20 h-20'
/>
) : <p>No Avatar</p>
}
</div>
<div className={'mb-4'}>
<p className={'block font-bold mb-2'}>App Role</p>
<p>{users?.app_role?.name ?? 'No data'}</p>
</div>
<>
<p className={'block font-bold mb-2'}>Custom Permissions</p>
<CardBox
className='mb-6 border border-gray-300 rounded overflow-hidden'
hasTable
>
<div className='overflow-x-auto'>
<table>
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody>
{users.custom_permissions && Array.isArray(users.custom_permissions) &&
users.custom_permissions.map((item: any) => (
<tr key={item.id} onClick={() => router.push(`/permissions/permissions-view/?id=${item.id}`)}>
<td data-label="name">
{ item.name }
</td>
</tr>
))}
</tbody>
</table>
</div>
{!users?.custom_permissions?.length && <div className={'text-center py-4'}>No data</div>}
</CardBox>
</>
<>
<p className={'block font-bold mb-2'}>Time Off Requests</p>
<CardBox
className='mb-6 border border-gray-300 rounded overflow-hidden'
hasTable
>
<div className='overflow-x-auto'>
<table>
<thead>
<tr>
<th>Type</th>
<th>Kind</th>
<th>Start</th>
<th>Finish</th>
<th>Hours</th>
<th>Days</th>
<th>Status</th>
<th>Requires Approval</th>
<th>Submitted At</th>
<th>Decided At</th>
<th>Reason</th>
<th>Manager Note</th>
<th>External Reference</th>
</tr>
</thead>
<tbody>
{users.time_off_requests_requester && Array.isArray(users.time_off_requests_requester) &&
users.time_off_requests_requester.map((item: any) => (
<tr key={item.id} onClick={() => router.push(`/time_off_requests/time_off_requests-view/?id=${item.id}`)}>
<td data-label="leave_type">
{ leaveTypeLabels[item.leave_type] || item.leave_type }
</td>
<td data-label="request_kind">
{ item.request_kind }
</td>
<td data-label="starts_at">
{ dataFormatter.dateTimeFormatter(item.starts_at) }
</td>
<td data-label="ends_at">
{ dataFormatter.dateTimeFormatter(item.ends_at) }
</td>
<td data-label="hours">
{ item.hours }
</td>
<td data-label="days">
{ item.days }
</td>
<td data-label="status">
{ item.status }
</td>
<td data-label="requires_approval">
{ dataFormatter.booleanFormatter(item.requires_approval) }
</td>
<td data-label="submitted_at">
{ dataFormatter.dateTimeFormatter(item.submitted_at) }
</td>
<td data-label="decided_at">
{ dataFormatter.dateTimeFormatter(item.decided_at) }
</td>
<td data-label="reason">
{ item.reason }
</td>
<td data-label="manager_note">
{ item.manager_note }
</td>
<td data-label="external_reference">
{ item.external_reference }
</td>
</tr>
))}
</tbody>
</table>
</div>
{!users?.time_off_requests_requester?.length && <div className={'text-center py-4'}>No data</div>}
</CardBox>
</>
<>
<p className={'block font-bold mb-2'}>Approvals</p>
<CardBox
className='mb-6 border border-gray-300 rounded overflow-hidden'
hasTable
>
<div className='overflow-x-auto'>
<table>
<thead>
<tr>
<th>Type</th>
<th>Kind</th>
<th>Start</th>
<th>Finish</th>
<th>Hours</th>
<th>Days</th>
<th>Status</th>
<th>Requires Approval</th>
<th>Submitted At</th>
<th>Decided At</th>
<th>Reason</th>
<th>Manager Note</th>
<th>External Reference</th>
</tr>
</thead>
<tbody>
{users.time_off_requests_approver && Array.isArray(users.time_off_requests_approver) &&
users.time_off_requests_approver.map((item: any) => (
<tr key={item.id} onClick={() => router.push(`/time_off_requests/time_off_requests-view/?id=${item.id}`)}>
<td data-label="leave_type">
{ leaveTypeLabels[item.leave_type] || item.leave_type }
</td>
<td data-label="request_kind">
{ item.request_kind }
</td>
<td data-label="starts_at">
{ dataFormatter.dateTimeFormatter(item.starts_at) }
</td>
<td data-label="ends_at">
{ dataFormatter.dateTimeFormatter(item.ends_at) }
</td>
<td data-label="hours">
{ item.hours }
</td>
<td data-label="days">
{ item.days }
</td>
<td data-label="status">
{ item.status }
</td>
<td data-label="requires_approval">
{ dataFormatter.booleanFormatter(item.requires_approval) }
</td>
<td data-label="submitted_at">
{ dataFormatter.dateTimeFormatter(item.submitted_at) }
</td>
<td data-label="decided_at">
{ dataFormatter.dateTimeFormatter(item.decided_at) }
</td>
<td data-label="reason">
{ item.reason }
</td>
<td data-label="manager_note">
{ item.manager_note }
</td>
<td data-label="external_reference">
{ item.external_reference }
</td>
</tr>
))}
</tbody>
</table>
</div>
{!users?.time_off_requests_approver?.length && <div className={'text-center py-4'}>No data</div>}
</CardBox>
</>
<>
<p className={'block font-bold mb-2'}>Time Off History</p>
<CardBox
className='mb-6 border border-gray-300 rounded overflow-hidden'
hasTable
>
<div className='overflow-x-auto'>
<table>
<thead>
<tr>
<th>Entry Type</th>
<th>Leave Bucket</th>
<th>Effective At</th>
<th>Calendar Year</th>
<th>Amount Hours</th>
<th>Amount Days</th>
<th>Counts Against Balance</th>
<th>Posting Status</th>
<th>Memo</th>
<th>Entered At</th>
</tr>
</thead>
<tbody>
{users.pto_journal_entries_user && Array.isArray(users.pto_journal_entries_user) &&
users.pto_journal_entries_user.map((item: any) => (
<tr key={item.id} onClick={() => router.push(`/pto_journal_entries/pto_journal_entries-view/?id=${item.id}`)}>
<td data-label="entry_type">
{ item.entry_type }
</td>
<td data-label="leave_bucket">
{ leaveTypeLabels[item.leave_bucket] || item.leave_bucket }
</td>
<td data-label="effective_at">
{ dataFormatter.dateTimeFormatter(item.effective_at) }
</td>
<td data-label="calendar_year">
{ item.calendar_year }
</td>
<td data-label="amount_hours">
{ item.amount_hours }
</td>
<td data-label="amount_days">
{ item.amount_days }
</td>
<td data-label="counts_against_balance">
{ dataFormatter.booleanFormatter(item.counts_against_balance) }
</td>
<td data-label="posting_status">
{ item.posting_status }
</td>
<td data-label="memo">
{ item.memo }
</td>
<td data-label="entered_at">
{ dataFormatter.dateTimeFormatter(item.entered_at) }
</td>
</tr>
))}
</tbody>
</table>
</div>
{!users?.pto_journal_entries_user?.length && <div className={'text-center py-4'}>No data</div>}
</CardBox>
</>
<>
<p className={'block font-bold mb-2'}>Time Off Entries Created</p>
<CardBox
className='mb-6 border border-gray-300 rounded overflow-hidden'
hasTable
>
<div className='overflow-x-auto'>
<table>
<thead>
<tr>
<th>Entry Type</th>
<th>Leave Bucket</th>
<th>Effective At</th>
<th>Calendar Year</th>
<th>Amount Hours</th>
<th>Amount Days</th>
<th>Counts Against Balance</th>
<th>Posting Status</th>
<th>Memo</th>
<th>Entered At</th>
</tr>
</thead>
<tbody>
{users.pto_journal_entries_entered_by && Array.isArray(users.pto_journal_entries_entered_by) &&
users.pto_journal_entries_entered_by.map((item: any) => (
<tr key={item.id} onClick={() => router.push(`/pto_journal_entries/pto_journal_entries-view/?id=${item.id}`)}>
<td data-label="entry_type">
{ item.entry_type }
</td>
<td data-label="leave_bucket">
{ leaveTypeLabels[item.leave_bucket] || item.leave_bucket }
</td>
<td data-label="effective_at">
{ dataFormatter.dateTimeFormatter(item.effective_at) }
</td>
<td data-label="calendar_year">
{ item.calendar_year }
</td>
<td data-label="amount_hours">
{ item.amount_hours }
</td>
<td data-label="amount_days">
{ item.amount_days }
</td>
<td data-label="counts_against_balance">
{ dataFormatter.booleanFormatter(item.counts_against_balance) }
</td>
<td data-label="posting_status">
{ item.posting_status }
</td>
<td data-label="memo">
{ item.memo }
</td>
<td data-label="entered_at">
{ dataFormatter.dateTimeFormatter(item.entered_at) }
</td>
</tr>
))}
</tbody>
</table>
</div>
{!users?.pto_journal_entries_entered_by?.length && <div className={'text-center py-4'}>No data</div>}
</CardBox>
</>
<>
<p className={'block font-bold mb-2'}>Yearly Leave Summary</p>
<CardBox
className='mb-6 border border-gray-300 rounded overflow-hidden'
hasTable
>
<div className='overflow-x-auto'>
<table>
<thead>
<tr>
<th>Calendar Year</th>
<th>PTO Pending</th>
<th>PTO Scheduled</th>
<th>PTO Taken</th>
<th>PTO Available</th>
<th>Medical Taken</th>
<th>Bereavement Taken</th>
<th>Time In Lieu Available</th>
<th>Vacation Pay Paid</th>
</tr>
</thead>
<tbody>
{users.yearly_leave_summaries_user && Array.isArray(users.yearly_leave_summaries_user) &&
users.yearly_leave_summaries_user.map((item: any) => (
<tr key={item.id} onClick={() => router.push(`/yearly_leave_summaries/yearly_leave_summaries-view/?id=${item.id}`)}>
<td data-label="calendar_year">
{ item.calendar_year }
</td>
<td data-label="pto_pending_days">
{ item.pto_pending_days }
</td>
<td data-label="pto_scheduled_days">
{ item.pto_scheduled_days }
</td>
<td data-label="pto_taken_days">
{ item.pto_taken_days }
</td>
<td data-label="pto_available_days">
{ item.pto_available_days }
</td>
<td data-label="medical_taken_days">
{ item.medical_taken_days }
</td>
<td data-label="bereavement_taken_days">
{ item.bereavement_taken_days }
</td>
<td data-label="time_in_lieu_available_days">
{ item.time_in_lieu_available_days }
</td>
<td data-label="vacation_pay_paid_amount">
{ item.vacation_pay_paid_amount }
</td>
</tr>
))}
</tbody>
</table>
</div>
{!users?.yearly_leave_summaries_user?.length && <div className={'text-center py-4'}>No data</div>}
</CardBox>
</>
<>
<p className={'block font-bold mb-2'}>Calendar Events</p>
<CardBox
className='mb-6 border border-gray-300 rounded overflow-hidden'
hasTable
>
<div className='overflow-x-auto'>
<table>
<thead>
<tr>
<th>Event Type</th>
<th>Title</th>
<th>Start</th>
<th>Finish</th>
<th>All Day</th>
<th>Notes</th>
</tr>
</thead>
<tbody>
{users.office_calendar_events_user && Array.isArray(users.office_calendar_events_user) &&
users.office_calendar_events_user.map((item: any) => (
<tr key={item.id} onClick={() => router.push(`/office_calendar_events/office_calendar_events-view/?id=${item.id}`)}>
<td data-label="event_type">
{ item.event_type }
</td>
<td data-label="title">
{ item.title }
</td>
<td data-label="starts_at">
{ dataFormatter.dateTimeFormatter(item.starts_at) }
</td>
<td data-label="ends_at">
{ dataFormatter.dateTimeFormatter(item.ends_at) }
</td>
<td data-label="is_all_day">
{ dataFormatter.booleanFormatter(item.is_all_day) }
</td>
<td data-label="notes">
{ item.notes }
</td>
</tr>
))}
</tbody>
</table>
</div>
{!users?.office_calendar_events_user?.length && <div className={'text-center py-4'}>No data</div>}
</CardBox>
</>
<>
<p className={'block font-bold mb-2'}>Approval Tasks</p>
<CardBox
className='mb-6 border border-gray-300 rounded overflow-hidden'
hasTable
>
<div className='overflow-x-auto'>
<table>
<thead>
<tr>
<th>State</th>
<th>Due At</th>
<th>Completed At</th>
<th>Summary</th>
</tr>
</thead>
<tbody>
{users.approval_tasks_assigned_manager && Array.isArray(users.approval_tasks_assigned_manager) &&
users.approval_tasks_assigned_manager.map((item: any) => (
<tr key={item.id} onClick={() => router.push(`/approval_tasks/approval_tasks-view/?id=${item.id}`)}>
<td data-label="state">
{ item.state }
</td>
<td data-label="due_at">
{ dataFormatter.dateTimeFormatter(item.due_at) }
</td>
<td data-label="completed_at">
{ dataFormatter.dateTimeFormatter(item.completed_at) }
</td>
<td data-label="summary">
{ item.summary }
</td>
</tr>
))}
</tbody>
</table>
</div>
{!users?.approval_tasks_assigned_manager?.length && <div className={'text-center py-4'}>No data</div>}
</CardBox>
</>
<LoginHistoryTable userId={users?.id} />
<BaseDivider />
<BaseButton
color='info'
label='Back'
onClick={() => router.push('/users/users-list')}
/>
</CardBox>
</SectionMain>
</>
);
};
UsersView.getLayout = function getLayout(page: ReactElement) {
return (
<LayoutAuthenticated
permission={'READ_USERS'}
>
{page}
</LayoutAuthenticated>
)
}
export default UsersView;