Skip to content

Commit

Permalink
Merge pull request #70 from BCSDLab/feat/#65/fix-admin-info
Browse files Browse the repository at this point in the history
(계정분리 관련) 게시물 작성자 고정 / CUD 구역 생성
  • Loading branch information
Gwak-Seungju authored Nov 28, 2024
2 parents 7691566 + 2aa11b5 commit df1deee
Show file tree
Hide file tree
Showing 96 changed files with 1,044 additions and 648 deletions.
930 changes: 540 additions & 390 deletions .pnp.cjs

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
"@types/node": "^16.7.13",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"antd": "^5.11.2",
"antd": "^5.22.2",
"axios": "^0.27.2",
"dayjs": "^1.11.7",
"dayjs": "^1.11.13",
"eslint-plugin-jest": "^27.6.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
18 changes: 18 additions & 0 deletions src/components/common/HistoryArea/HistoryArea.style.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Card } from 'antd';
import styled from 'styled-components';

// eslint-disable-next-line import/prefer-default-export
export const HistoryArea = styled(Card)`
position: absolute;
bottom: 0;
right: 0;
z-index: 5;
width: 300px;
height: 110px;
overflow: auto;
border: none;
.ant-card-body {
padding: 0;
}
`;
25 changes: 25 additions & 0 deletions src/components/common/HistoryArea/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { List } from 'antd';
import { CardProps } from 'antd/lib';
import { HistoryInfo } from 'model/history.model';
import * as S from './HistoryArea.style';

interface HistoryAreaProps {
historys: HistoryInfo[],
creator?: string,
created_at?: string,
}

export default function HistoryArea({
historys, creator, created_at, ...args
}: HistoryAreaProps & CardProps) {
return (
<S.HistoryArea {...args}>
<List
dataSource={historys}
renderItem={(item) => <List.Item style={{ padding: '0', border: 'none' }}>{`${item.created_at} ${item.request_method} (${item.name})`}</List.Item>}
locale={{ emptyText: ' ' }}
/>
<div>{`${created_at} 생성 (${creator})`}</div>
</S.HistoryArea>
);
}
10 changes: 10 additions & 0 deletions src/model/auth.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ export interface LoginRequest {
password: string
}

export interface AdminInfo {
id: number;
email: string;
name: string;
track_name: string;
team_name: string;
can_create_admin: boolean;
super_admin: boolean;
}

export interface ChangePasswordRequest {
old_password: string,
new_password: string,
Expand Down
25 changes: 25 additions & 0 deletions src/model/history.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export interface HistoryInfo {
id: number;
domain_id: number;
name: string;
domain_name: string;
request_method: string;
request_message: string;
created_at: string;
}

export interface HistorysRequest {
page: number;
limit?: number;
requestMethod?: string;
domainName?: string;
domainId?: number;
}

export interface HistorysResponse {
total_count: number;
current_count: number;
total_page: number;
current_page: number;
historys: HistoryInfo[];
}
9 changes: 9 additions & 0 deletions src/pages/ABTest/components/ABTestDetail.style.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import styled from 'styled-components';

export * from './DeleteWarning.style';

export * from 'components/common/HistoryArea/HistoryArea.style';

export const Container = styled.div`
position: relative;
`;
19 changes: 15 additions & 4 deletions src/pages/ABTest/components/ABTestDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import {
} from '@ant-design/icons';
import { useNavigate, useParams } from 'react-router-dom';
import CustomForm from 'components/common/CustomForm';
import HistoryArea from 'components/common/HistoryArea';
import { useGetABTestQuery } from 'store/api/abtest';
import { useGetHistorysQuery } from 'store/api/history';
import { ABTest } from 'model/abTest.model';
import useBooleanState from 'utils/hooks/useBoolean';
import useABTestMutation from './hook/useABTestMutation';
import * as S from './DeleteWarning.style';
import * as S from './ABTestDetail.style';
import UserManageModal from './UserManageModal';

interface Variable {
Expand All @@ -31,6 +33,7 @@ export default function ABTestDetail() {
const [variables, setVariables] = useState<Variable[]>([]);
const [sliderValues, setSliderValues] = useState<number[]>([]);
const [winner, setWinner] = useState<string>('');
const { data: historys } = useGetHistorysQuery({ page: 1, domainId: Number(id) });

// eslint-disable-next-line max-len
const { value: checkModal, setTrue: checkModalOpen, setFalse: checkModalClose } = useBooleanState();
Expand Down Expand Up @@ -135,14 +138,14 @@ export default function ABTestDetail() {
};

return (
<>
<S.Container>
<CustomForm form={form} onFinish={onFinish}>
<Divider orientation="left">세부사항</Divider>
{renderStatusTag()}
<br />
<br />
<CustomForm.Input label="id" name="id" disabled />
<CustomForm.Input label="작성자" name="creator" maxLength={50} />
<CustomForm.Input label="작성자" name="creator" maxLength={50} disabled />
<CustomForm.Input label="소속팀" name="team" maxLength={50} />
<CustomForm.Input label="AB테스트의 제목" name="display_title" maxLength={255} />
<CustomForm.Input label="변수" name="title" disabled maxLength={255} />
Expand Down Expand Up @@ -220,6 +223,14 @@ export default function ABTestDetail() {
>
실험 인원 수동 추가, 수정 하기
</Button>
{(historys && abTestData) && (
<HistoryArea
historys={historys.historys}
creator={abTestData.creator}
created_at={abTestData.created_at}
/>
)}

<Modal
open={checkModal}
onCancel={checkModalClose}
Expand Down Expand Up @@ -276,6 +287,6 @@ export default function ABTestDetail() {
</S.Item>
</S.AroundRow>
</Modal>
</>
</S.Container>
);
}
6 changes: 2 additions & 4 deletions src/pages/ABTest/components/AddABTestModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ import * as S from './AddABTestModal.style';
import NewTest from './NewTest';
import useABTestMutation from './hook/useABTestMutation';

function AddABTestModal({ onCancel }: { onCancel: () => void }) {
function AddABTestModal({ onCancel, creator }: { onCancel: () => void, creator: string }) {
const [form] = CustomForm.useForm();
const [step, setStep] = useState(1);
const [title, setTitle] = useState('');
const [creator, setCreator] = useState('');
const [team, setTeam] = useState('');
const [displayTitle, setDisplayTitle] = useState('');
const [description, setDescription] = useState('');
Expand Down Expand Up @@ -80,7 +79,6 @@ function AddABTestModal({ onCancel }: { onCancel: () => void }) {
form.resetFields();
setStep(1);
setTitle('');
setCreator('');
setTeam('');
setDisplayTitle('');
setDescription('');
Expand Down Expand Up @@ -126,7 +124,7 @@ function AddABTestModal({ onCancel }: { onCancel: () => void }) {
{step === 1 && (
<S.StepContainer>
<S.Label>작성자</S.Label>
<S.Input onChange={(e) => setCreator(e.target.value)} maxLength={10} />
<S.Input value={creator} maxLength={10} disabled />
<S.Label>소속팀</S.Label>
<S.Input onChange={(e) => setTeam(e.target.value)} maxLength={10} />
<S.Label>AB테스트의 제목</S.Label>
Expand Down
4 changes: 3 additions & 1 deletion src/pages/ABTest/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import CustomForm from 'components/common/CustomForm';
import CustomTable from 'components/common/CustomTable';
import { useState } from 'react';
import { useGetABTestsQuery } from 'store/api/abtest';
import { useGetAdminInfoQuery } from 'store/api/auth';
import useBooleanState from 'utils/hooks/useBoolean';
import * as S from './ABTest.style';
import AddABTestModal from './components/AddABTestModal';
Expand All @@ -10,6 +11,7 @@ export default function ABTest() {
const [page, setPage] = useState(1);
const { data: abtestList } = useGetABTestsQuery({ page, limit: 10 });
const { value: isModalOpen, setTrue: openModal, setFalse: closeModal } = useBooleanState();
const { data: adminInfo } = useGetAdminInfoQuery();
return (
<S.Container>
<CustomForm.Modal
Expand All @@ -21,7 +23,7 @@ export default function ABTest() {
onCancel={closeModal}
onClick={openModal}
>
<AddABTestModal onCancel={closeModal} />
<AddABTestModal onCancel={closeModal} creator={adminInfo?.name || ''} />
</CustomForm.Modal>
{abtestList && (
<CustomTable
Expand Down
12 changes: 11 additions & 1 deletion src/pages/Services/Notice/NoticeDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
import { Editor } from '@toast-ui/react-editor';
import { useUploadfileMutation } from 'store/api/upload';
import { NoticeRequest, NoticeUpdateForm } from 'model/notice.model';
import { useGetHistorysQuery } from 'store/api/history';
import HistoryArea from 'components/common/HistoryArea';
import useNoticeMutation from './useNoticeMutation';
import * as S from './NoticeDetail.style';

Expand All @@ -27,6 +29,7 @@ export default function NoticeDetail() {
const [uploadfile] = useUploadfileMutation();
const { required } = CustomForm.validateUtils();
const [form] = CustomForm.useForm();
const { data: historys } = useGetHistorysQuery({ page: 1, domainId: Number(id) });

const handleFinish = (values: NoticeRequest) => {
const editorContent = editorRef.current?.getInstance().getHTML();
Expand Down Expand Up @@ -113,7 +116,14 @@ export default function NoticeDetail() {
{isEditing ? '저장' : '수정'}
</CustomForm.Button>
</S.ButtonWrapper>

{historys && (
<HistoryArea
historys={historys.historys}
creator={notice.author}
created_at={notice.created_at}
style={{ left: '20px', bottom: '-70px' }}
/>
)}
<Modal
title="공지사항 삭제 확인"
open={isModalOpen}
Expand Down
17 changes: 15 additions & 2 deletions src/store/api/auth/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { createApi } from '@reduxjs/toolkit/query/react';
import { LoginRequest, LoginResponse, ChangePasswordRequest } from 'model/auth.model';
import {
LoginRequest, LoginResponse, AdminInfo, ChangePasswordRequest,
} from 'model/auth.model';

import baseQueryReauth from 'store/api/baseQueryReauth';

export const authApi = createApi({
reducerPath: 'authApi',
tagTypes: ['admin'],
baseQuery: baseQueryReauth,
endpoints: (builder) => ({
login: builder.mutation<LoginResponse, LoginRequest>({
Expand All @@ -27,7 +31,16 @@ export const authApi = createApi({
body: { old_password, new_password },
}),
}),

getAdminInfo: builder.query<AdminInfo, void>({
query: () => ({
url: 'admin',
}),
providesTags: [{ type: 'admin', id: 'ADMIN' }],
}),
}),
});

export const { useLoginMutation, useProtectedMutation, useChangePasswordMutation } = authApi;
export const {
useLoginMutation, useProtectedMutation, useGetAdminInfoQuery, useChangePasswordMutation,
} = authApi;
24 changes: 24 additions & 0 deletions src/store/api/history/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { createApi } from '@reduxjs/toolkit/query/react';
import { HistorysRequest, HistorysResponse } from 'model/history.model';
import baseQueryReauth from 'store/api/baseQueryReauth';

export const historyApi = createApi({
reducerPath: 'historyApi',
tagTypes: ['historys'],

baseQuery: baseQueryReauth,

endpoints: (builder) => ({
getHistorys: builder.query<HistorysResponse, HistorysRequest>({
query: ({ page, domainId = null, limit = 30 }) => ({
url: `admin/historys?page=${page}&limit=${limit}${domainId ? `&domainId=${domainId}` : ''}`,
}),
providesTags: [{ type: 'historys', id: 'HISTORYS' }],
}),
}),
refetchOnMountOrArgChange: true,
});

export const {
useGetHistorysQuery,
} = historyApi;
2 changes: 2 additions & 0 deletions src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { abTestApi } from './api/abtest';
import { benefitApi } from './api/benefit';
import { forceUpdateApi } from './api/forceUpdate';
import { updateListApi } from './api/updateList';
import { historyApi } from './api/history';

const apiList = [
authApi,
Expand All @@ -36,6 +37,7 @@ const apiList = [
benefitApi,
forceUpdateApi,
updateListApi,
historyApi,
];

const apiMiddleware = apiList.map((api) => api.middleware);
Expand Down
1 change: 1 addition & 0 deletions src/styles/Detail.style.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import styled from 'styled-components';

export const Container = styled.div`
font-family: "Noto Sans KR", "Avenir", "Helvetica", "Arial", "sans-serif";
position: relative;
`;

export const BreadCrumb = styled.div`
Expand Down
Loading

0 comments on commit df1deee

Please sign in to comment.