Skip to content

Commit

Permalink
Merge pull request #91 from HGU-WALAB/#88/admin-dashboard
Browse files Browse the repository at this point in the history
#88/admin dashboard
  • Loading branch information
healim01 authored Jan 9, 2024
2 parents d3c70b5 + 6bd1657 commit 1b853b2
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 23 deletions.
4 changes: 1 addition & 3 deletions src/layouts/dashboard/config-navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { paths } from 'src/routes/paths';
// components
import SvgColor from 'src/components/svg-color';
import { useRecoilValue } from 'recoil';
import { DeptUrlState, userDeptState } from 'src/utils/atom';
import { userDeptState } from 'src/utils/atom';

// ----------------------------------------------------------------------

Expand Down Expand Up @@ -105,8 +105,6 @@ export function useUserNavData() {
url = userDeptInfo.link ?? '';
}

console.log(url);

const data = useMemo(
() => [
// OVERVIEW
Expand Down
6 changes: 1 addition & 5 deletions src/layouts/dashboard/dept-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ import { strlen } from 'stylis';
import { IDeptInfo } from 'src/types/dept';
// ----------------------------------------------------------------------

// const OPTIONS = ['CSEE 뉴턴', '오석관', '산학협력관', '에벤에셀'];

// const COLORS = ['secondary', 'info', 'success'];

const DeptButton = styled.div`
display: flex;
flex-direction: row;
Expand Down Expand Up @@ -178,7 +174,7 @@ export default function DeptHeaderButton() {
</Avatar>
{option.deptName}

{option.deptMemberResponse[0].deptRole === 'Admin' ? (
{option.deptMemberResponse[0].deptRole === 'ADMIN' ? (
<Avatar
alt="A"
color="primary.pale"
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/dashboard/nav-vertical.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default function NavVertical({ openNav, onCloseNav }: Props) {
<Box style={{ height: '10px' }} />

{typeof userDeptInfo === 'object' &&
userDeptInfo.deptMemberResponse[0].deptRole === 'Admin' ? (
userDeptInfo.deptMemberResponse[0].deptRole === 'ADMIN' ? (
<NavSectionVertical
data={navData}
config={{
Expand Down
2 changes: 1 addition & 1 deletion src/pages/dashboard/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function Page() {
</Helmet>

{typeof userDeptInfo === 'object' &&
userDeptInfo.deptMemberResponse[0].deptRole === 'Admin' ? (
userDeptInfo.deptMemberResponse[0].deptRole === 'ADMIN' ? (
<AdminDashboardView />
) : (
<UserDashboardView />
Expand Down
19 changes: 12 additions & 7 deletions src/sections/dashboard/admin-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { useState } from 'react';
import { Link } from 'react-router-dom';
import { paths } from 'src/routes/paths';
import styled from 'styled-components';
import { userDeptState } from 'src/utils/atom';
import { useRecoilValue } from 'recoil';
import AnalyticsWidgetSummary from './analytics-widget-summary';
import { UserCalendarView } from './calendar/view';
// import AdminCalendarView from './calendar/view/admin-calendar-view';
Expand All @@ -30,6 +32,12 @@ export default function AdminDashboardView() {
const settings = useSettingsContext();
const theme = useTheme();

const userDeptInfo = useRecoilValue(userDeptState);
let url = '';
if (typeof userDeptInfo === 'object') {
url = userDeptInfo.link ?? '';
}

const rangeCalendarPicker = useDateRangePicker(new Date(), null);
const [value, setValue] = useState<Date | null>(new Date());

Expand Down Expand Up @@ -57,7 +65,7 @@ export default function AdminDashboardView() {
{/* 분석 카드 4개 */}
<Grid container spacing={3}>
<Grid xs={12} sm={6} md={3}>
<StyledLink to={paths.dept.reservelist('CSEE')}>
<StyledLink to={paths.dept.reservelist(url)}>
<AnalyticsWidgetSummary
title="미승인 예약"
total={210}
Expand All @@ -68,7 +76,7 @@ export default function AdminDashboardView() {
</Grid>

<Grid xs={12} sm={6} md={3}>
<StyledLink to={paths.dept.reservelist('CSEE')}>
<StyledLink to={paths.dept.management.manageUser(url)}>
<AnalyticsWidgetSummary
title="미승인 대기 유저"
total={13}
Expand All @@ -79,7 +87,7 @@ export default function AdminDashboardView() {
</Grid>

<Grid xs={12} sm={6} md={3}>
<StyledLink to={paths.dept.reservelist('CSEE')}>
<StyledLink to={paths.dept.reservelist(url)}>
<AnalyticsWidgetSummary
title="오늘 예정된 예약"
total={17}
Expand All @@ -90,7 +98,7 @@ export default function AdminDashboardView() {
</Grid>

<Grid xs={12} sm={6} md={3}>
<StyledLink to={paths.dept.reservelist('CSEE')}>
<StyledLink to={paths.dept.reservelist(url)}>
<AnalyticsWidgetSummary
title="전체 예약"
total={234}
Expand All @@ -106,9 +114,6 @@ export default function AdminDashboardView() {
{/* <AdminCalendarView /> */}
</Grid>
</Grid>

{/* </DemoItem> */}
{/* </Box> */}
</Container>
);
}
12 changes: 7 additions & 5 deletions src/sections/home/dept-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IDeptInfo } from 'src/types/dept';
import { useEffect, useState } from 'react';
import axiosInstance, { endpoints } from 'src/utils/axios';
import { useRecoilValue, useSetRecoilState } from 'recoil';
import { DeptUrlState, userState } from 'src/utils/atom';
import { DeptUrlState, userDeptState, userState } from 'src/utils/atom';
import { paths } from 'src/routes/paths';

// 0 입장 가능
Expand All @@ -22,6 +22,7 @@ export default function DeptCard({ deptInfo, onAccess, onPending }: Props) {
const [deptStatus, setDeptStatus] = useState<string>('');
const userInfo = useRecoilValue(userState);
const setDeptUrl = useSetRecoilState(DeptUrlState);
const setDeptState = useSetRecoilState(userDeptState);

useEffect(() => {
const firstElement = deptInfo.deptMemberResponse[0];
Expand All @@ -39,13 +40,14 @@ export default function DeptCard({ deptInfo, onAccess, onPending }: Props) {
}
}, [deptInfo]);

const handleMove = (deptlink: string | null) => {
setDeptUrl(paths.dept.dashboard(deptlink ?? 'HANSPACE'));
window.location.href = paths.dept.dashboard(deptlink ?? 'HANSPACE');
const handleMove = (deptinfo: IDeptInfo | null) => {
setDeptUrl(paths.dept.dashboard(deptinfo?.link ?? 'HANSPACE'));
setDeptState(deptinfo ?? 'HANSPACE');
window.location.href = paths.dept.dashboard(deptinfo?.link ?? 'HANSPACE');
};

const handleClick = (access: boolean, status: string) => {
if (status === '관리하기' || status === '입장하기') handleMove(deptInfo.link);
if (status === '관리하기' || status === '입장하기') handleMove(deptInfo);
else if (access === true && status === '기관 추가하기') {
axiosInstance.post(endpoints.dept.add, {
name: userInfo.name,
Expand Down
21 changes: 20 additions & 1 deletion src/sections/home/success-modal-accessed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { useBoolean } from 'src/hooks/use-boolean';
import { IDeptInfo } from 'src/types/dept';
import styled from 'styled-components';
import { Box } from '@mui/material';
import { paths } from 'src/routes/paths';
import { useSetRecoilState } from 'recoil';
import { DeptUrlState } from 'src/utils/atom';

// ----------------------------------------------------------------------

Expand All @@ -31,6 +34,13 @@ const Content = styled.div`
`;

export default function AccessedDialog({ open, onClose, currentDept }: IAccessModalProps) {
const setDeptUrl = useSetRecoilState(DeptUrlState);

const moveToDept = (deptlink: string | null | undefined) => {
setDeptUrl(paths.dept.dashboard(deptlink ?? 'HANSPACE'));
window.location.href = paths.dept.dashboard(deptlink ?? 'HANSPACE');
};

return (
<Dialog open={open} onClose={onClose}>
<Box style={{ padding: '30px', textAlign: 'center' }}>
Expand All @@ -54,13 +64,22 @@ export default function AccessedDialog({ open, onClose, currentDept }: IAccessMo
<Box style={{ padding: '24px', textAlign: 'center' }}>
<Button
variant="contained"
onClick={onClose}
onClick={() => moveToDept(currentDept?.link)}
color="primary"
autoFocus
style={{ padding: '15px 50px' }}
>
기관 둘러보기
</Button>
<Button
variant="contained"
onClick={onClose}
color="primary"
autoFocus
style={{ padding: '15px 50px' }}
>
홈으로
</Button>
</Box>
</Box>
</Dialog>
Expand Down

0 comments on commit 1b853b2

Please sign in to comment.