Skip to content

Commit

Permalink
[v0.0.4] 유저 조회 기본기능 배포
Browse files Browse the repository at this point in the history
[v0.0.4] 유저 조회 기본기능 배포
  • Loading branch information
ImNM authored Aug 2, 2022
2 parents 0e0cf1a + f3830a1 commit 4f60952
Show file tree
Hide file tree
Showing 15 changed files with 225 additions and 35 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@

npm-debug.log*
yarn-debug.log*
yarn-error.log*
public
yarn-error.log*
public
20 changes: 1 addition & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/apis/users/UsersApi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { default: axios } = require('axios');

const { default: InstanceSetting } = require('../common/instance.api');
4 changes: 2 additions & 2 deletions src/components/Tables/OrdersPage/OrdersPage.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import React from 'react';

function OrdersPage() {
return <div>OrdersPage</div>;
return <div>봉세환의 OrdersPage</div>;
}

export default OrdersPage;
4 changes: 2 additions & 2 deletions src/components/Tables/TicketsPage/TicketsPage.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import React from 'react';

function TicketsPage() {
return <div>TicketsPage</div>;
return <div>티켓 페이지</div>;
}

export default TicketsPage;
76 changes: 76 additions & 0 deletions src/components/Tables/UsersPage/Table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import React, { useState, useEffect } from 'react';

import { useSelector, useDispatch } from 'react-redux';
import { Table } from 'antd';
import { usersPage } from '../../../state/actions-creators/usersPage';
import moment from 'moment';
const { Column } = Table;

function UsersPageTable() {
const dispatch = useDispatch();
const { data, pending } = useSelector(state => state.usersPage);
const [page, setPage] = useState(1);

const onPageChange = e => {
// 페이지네이션 번호 바뀔때 뜸.
console.log(e);
setPage(e);
dispatch(
usersPage({
requestPage: e
})
);
};

useEffect(() => {
dispatch(
usersPage({
requestPage: 1
})
);
}, [dispatch]);

// 받을 수 있는 정보 목록
// {
// "id": 3,
// "name": "강나연",
// "phoneNumber": "01075546670",
// "role": "Admin",
// "ticketNum": 0
// },

return (
<>
<Table
loading={pending}
pagination={{
current: page,
pageSize: 10,
total: data ? data.total : 0,
showSizeChanger: false,
onChange: onPageChange
}}
key="id"
rowKey="id"
pageSize={10}
dataSource={data ? data.userList : []}
>
<Column title="유저" dataIndex="id" key="id" />
<Column title="입금자명" dataIndex="name" key="id" />
<Column title="전화번호" dataIndex="phoneNumber" key="id" />
<Column title="구입한 티켓 매수" dataIndex="ticketNum" key="id" />
<Column
title="가입일"
dataIndex="createAt"
key="id"
render={element => {
return moment(new Date(element)).format('MM월 DD일');
}}
/>
<Column title="어드민 여부" dataIndex="role" key="id" />
</Table>
</>
);
}

export default UsersPageTable;
43 changes: 43 additions & 0 deletions src/components/Tables/UsersPage/UserSearch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Button, Input, Select } from 'antd';
import React, { useState } from 'react';
const { Option } = Select;

function UserSearch() {
const [searchOption, setSearchOption] = useState('입금자명');

const onOptionChange = e => {
console.log(e);
if (e === '1') {
setSearchOption('입금자명');
} else {
setSearchOption('전화번호');
}
};

return (
<>
<div className="site-input-group-wrapper">
<Input.Group compact>
<Select defaultValue="입금자명" onChange={onOptionChange}>
<Option key="1" value="1">
입금자명
</Option>
<Option key="2" value="2">
전화번호
</Option>
</Select>
<Input
style={{
width: 'calc(100% - 200px)'
}}
placeholder={`${searchOption} 입력`}
/>
<Button type="primary">검색</Button>
</Input.Group>
<br />
</div>
</>
);
}

export default UserSearch;
11 changes: 9 additions & 2 deletions src/components/Tables/UsersPage/UsersPage.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import React from "react";
import React from 'react';
import UsersPageTable from './Table';
import UserSearch from './UserSearch';

function UsersPage() {
return <div>UsersPage</div>;
return (
<div>
<UserSearch />
<UsersPageTable />
</div>
);
}

export default UsersPage;
12 changes: 6 additions & 6 deletions src/hoc/AuthPass.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from "react";
import { Navigate } from "react-router-dom";
import React from 'react';
import { Navigate } from 'react-router-dom';

import { useSelector } from "react-redux";
import { useSelector } from 'react-redux';

const requireAuth =
(Component) =>
Component =>
({ ...props }) => {
const { authenticated } = useSelector((state) => state.auth);
const { authenticated } = useSelector(state => state.auth);

console.log("인증 부분 검사", authenticated, !authenticated);
console.log('인증 부분 검사', authenticated, !authenticated);

return authenticated === false ? (
<Component {...props} />
Expand Down
1 change: 1 addition & 0 deletions src/state/action-types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './slackMessage';
export * from './slackValidation';
export * from './logout';
export * from './examplePagination';
export * from './usersPage';
3 changes: 3 additions & 0 deletions src/state/action-types/usersPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const USER_PAGE_PENDING = 'USER_PAGE_PENDING';
export const USER_PAGE_SUCCESS = 'USER_PAGE_SUCCESS';
export const USER_PAGE_ERROR = 'USER_PAGE_ERROR';
2 changes: 1 addition & 1 deletion src/state/actions-creators/logout.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import TicketsApi from '../../apis/tickets/TicketsApi';
export const logout = callback => async dispatch => {
dispatch({ type: LOGOUT_USER });

localStorage.setItem('accessToken', null);
localStorage.removeItem('accessToken');
axios.defaults.headers.common.Authorization = null;

// 자동으로 피쳐로 넘어가게끔
Expand Down
34 changes: 34 additions & 0 deletions src/state/actions-creators/usersPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import axios from 'axios';
import {
USER_PAGE_PENDING,
USER_PAGE_SUCCESS,
USER_PAGE_ERROR
} from '../action-types';

export const usersPage =
({ requestPage }, callback) =>
async dispatch => {
try {
dispatch({ type: USER_PAGE_PENDING });

const response = await axios.get(
`https://api.gosrock.band/v1/users/all?order=ASC&page=${requestPage}&take=10`
);

console.log('포토 조회액션1', response);

const data = {
total: response.data.data.meta.itemCount,
currentPage: requestPage,
userList: response.data.data.data
};

dispatch({ type: USER_PAGE_SUCCESS, payload: data });

// 자동으로 피쳐로 넘어가게끔
// callback();
} catch (e) {
//400 ~
dispatch({ type: USER_PAGE_ERROR, payload: '조회 실패' });
}
};
4 changes: 3 additions & 1 deletion src/state/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { combineReducers } from 'redux';
import { auth } from './auth';
import examplePagination from './examplePagination';
import slackMessage from './slackMessage';
import usersPage from './usersPage';

export default combineReducers({
slackMessage: slackMessage,
auth: auth,
examplePagination: examplePagination
examplePagination: examplePagination,
usersPage: usersPage
});
39 changes: 39 additions & 0 deletions src/state/reducers/usersPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {
USER_PAGE_PENDING,
USER_PAGE_SUCCESS,
USER_PAGE_ERROR
} from '../action-types';

// eslint-disable-next-line import/no-anonymous-default-export
export default function (
state = {
data: {
totalPage: 0,
currentPage: 1,
userList: []
},
error: null,
pending: false
},
action
) {
switch (action.type) {
case USER_PAGE_PENDING:
return { ...state, data: action.payload, error: null, pending: true };
case USER_PAGE_SUCCESS:
return { ...state, data: action.payload, error: null, pending: false };
case USER_PAGE_ERROR:
return {
...state,
data: {
totalPage: 0,
currentPage: 1,
userList: []
},
error: action.payload,
pending: false
};
default:
return state;
}
}

0 comments on commit 4f60952

Please sign in to comment.