diff --git a/src/components/setting/address/AddressCardList.tsx b/src/components/setting/address/AddressCardList.tsx
index 0a0d161..7206f18 100644
--- a/src/components/setting/address/AddressCardList.tsx
+++ b/src/components/setting/address/AddressCardList.tsx
@@ -1,34 +1,58 @@
+import { useState, useEffect } from 'react';
+
+import { useDeletAdress, useGetAdressList } from 'src/modules/auth';
import AddressCardItem from './AddressCardItem';
-const data = [
- {
- id: 1,
- title: '회사 1',
- mainAddress: '서울특별시 영등포구 여의대로 14 KT여의도타워 14층 A회사',
- detailAdress: '상세주소',
- phone: '010-1234-1234',
- },
- {
- id: 2,
- title: '우리집',
- mainAddress: '서울특별시 영등포구 여의대로 14 KT여의도타워 14층 A회사',
- detailAdress: '상세주소',
- phone: '010-3412-1234',
- },
-];
+type ItemTypes = {
+ id: number;
+ address: string;
+ detail: string;
+ addressName: null | string;
+ phone?: string;
+};
-const AddressCardList = () => (
-
- {data.map((item) => (
-
- ))}
-
-);
+const AddressCardList = () => {
+ const mutaiton = useGetAdressList();
+ const delMutaion = useDeletAdress();
+ const [data, setData] = useState([]);
+ // 주소지역 가져오기
+ const getAddressList = async () => {
+ try {
+ const result = await mutaiton.mutateAsync({ id: 10 });
+ console.log(result);
+ setData(result);
+ } catch (error) {
+ console.log(error);
+ }
+ };
+ // 주소 삭제하기
+ const onDelete = async (addressId: number): Promise
=> {
+ try {
+ await delMutaion.mutateAsync({ id: 10, addresId: addressId });
+ getAddressList();
+ } catch (error) {
+ console.error(error);
+ window.alert(error.response?.data.message);
+ }
+ };
+ useEffect(() => {
+ getAddressList();
+ }, []);
+ return (
+
+ {data.map((item: ItemTypes) => (
+
+ ))}
+
+ );
+};
export default AddressCardList;
diff --git a/src/interfaces/auth.ts b/src/interfaces/auth.ts
index bdbddd7..a4999a7 100644
--- a/src/interfaces/auth.ts
+++ b/src/interfaces/auth.ts
@@ -2,3 +2,16 @@ export type loginTypes = {
email: string;
password: string;
};
+
+export type userTypes = {
+ id: number;
+};
+
+export type addressType = {
+ id: number;
+ addressName: string;
+ address: string;
+ detail: string;
+ isDefault: boolean;
+ zipCode: string;
+};
diff --git a/src/modules/auth.ts b/src/modules/auth.ts
index 92763fb..5889ef6 100644
--- a/src/modules/auth.ts
+++ b/src/modules/auth.ts
@@ -1,18 +1,20 @@
import axios from 'axios';
import { useMutation, useQuery } from 'react-query';
-import { loginTypes } from 'src/interfaces/auth';
+import { addressType, loginTypes, userTypes } from 'src/interfaces/auth';
const signUpKey = () => ['auth', 'signup'];
const loginKey = () => ['auth', 'login'];
const userKey = () => ['auth', 'user'];
+const addAddressKey = () => ['auth', 'addAddress'];
+const addressListKey = () => ['auth', 'addressList'];
+const deleteAddressKey = () => ['auth', 'deleteAddress'];
export const getSignUpApi = async (data: loginTypes) => {
axios.defaults.baseURL = `${process.env.API_URL}:8086`;
const res = await axios.post(`users/sign-up`, data);
return res.data;
};
-
export const useSignUpMutation = () => useMutation(signUpKey(), getSignUpApi);
const getLoginApi = async (data: loginTypes) => {
@@ -20,12 +22,31 @@ const getLoginApi = async (data: loginTypes) => {
console.log(res);
return res.data.data;
};
-
export const useLoginMutation = () => useMutation(loginKey(), getLoginApi);
-const getUserApi = () => {
- // todo
- console.log('유저 api');
+// 유저 정보 가져오기
+const getUserApi = async (data: userTypes) => {
+ const res = await axios.get(`/users/${data.id}`);
+ console.log(res);
+ return res.data.data;
};
+export const useUserDataMutation = () => useMutation(userKey(), getUserApi);
-export const useUserDataQuery = () => useQuery(userKey(), getUserApi);
+// 배송지 목록
+const getAddressListApi = async (data: userTypes) => {
+ const res = await axios.get(`/users/${data.id}/address`);
+ return res.data.data;
+};
+export const useGetAdressList = () => useMutation(addressListKey(), getAddressListApi);
+// 배송지 등록
+const addAddressApi = async (data: addressType) => {
+ const res = await axios.post(`/users/${data.id}/address`, data);
+ return res.data.data;
+};
+export const useAddAdress = () => useMutation(addAddressKey(), addAddressApi);
+// 배송지 삭제
+const deleteAddressApi = async (data: { id: number; addresId: number }) => {
+ const res = await axios.delete(`/users/${data.id}/address/${data.addresId}`);
+ return res.data.data;
+};
+export const useDeletAdress = () => useMutation(deleteAddressKey(), deleteAddressApi);
diff --git a/src/pages/market/orderAdmin.tsx b/src/pages/market/orderAdmin.tsx
new file mode 100644
index 0000000..aaf19c9
--- /dev/null
+++ b/src/pages/market/orderAdmin.tsx
@@ -0,0 +1,93 @@
+import { css, Theme } from '@emotion/react';
+import TopBar from 'src/components/common/layout/TopBar';
+import Select from 'src/components/common/Select';
+import Button from 'src/components/common/Button';
+import OrderAdminList from 'src/components/market/orderAdminList';
+
+const OrederAdmin = () => (
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+);
+
+const containerCss = (theme: Theme) => css`
+ section {
+ padding: 30px 0;
+
+ > .selectBox {
+ padding: 0 1.2em 1.875em;
+ border-bottom: 10px solid ${theme.color.grey020};
+
+ select {
+ margin: 0;
+ width: 100%;
+ border-radius: 6px;
+ border: 1px solid ${theme.color.grey030};
+ height: 54px;
+ }
+ }
+
+ .allSelectBox {
+ display: flex;
+ align-items: center;
+ padding: 8px 1.2em;
+ > input {
+ border: 1px solid ${theme.color.grey040};
+ margin-right: 20px;
+ width: 16px;
+ height: 16px;
+ }
+ > div:nth-child(2) {
+ flex: 1;
+ }
+ .selectBox {
+ select {
+ padding: 0 20px 0 10px;
+ height: 32px;
+ border: 1px solid ${theme.color.grey030};
+ border-radius: 3px;
+ option {
+ font-size: ${theme.fontSize.caption1};
+ color: ${theme.color.grey060};
+ }
+ }
+ }
+ }
+ }
+`;
+
+const selectCss = () => css`
+ div {
+ right: 5%;
+ }
+`;
+
+const btnCss = () => css`
+ width: 75px;
+ border-radius: 3px;
+`;
+
+export default OrederAdmin;
diff --git a/src/pages/market/orderAdminDetail.tsx b/src/pages/market/orderAdminDetail.tsx
new file mode 100644
index 0000000..8e8caba
--- /dev/null
+++ b/src/pages/market/orderAdminDetail.tsx
@@ -0,0 +1,9 @@
+import TopBar from 'src/components/common/layout/TopBar';
+
+const OrderAdminDetail = () => (
+ <>
+
+ >
+);
+
+export default OrderAdminDetail;
diff --git a/src/pages/setting/addressAdd.tsx b/src/pages/setting/addressAdd.tsx
index c6b05fa..4d29f4f 100644
--- a/src/pages/setting/addressAdd.tsx
+++ b/src/pages/setting/addressAdd.tsx
@@ -5,12 +5,14 @@ import CheckBox from 'src/components/common/CheckBox';
import { useForm, DeepMap, FieldError } from 'react-hook-form';
import { css, Theme } from '@emotion/react';
import { useState } from 'react';
+import { useAddAdress } from 'src/modules/auth';
+import router from 'next/router';
type FormData = {
- deliveryName?: string;
+ addressName?: string;
name?: string;
address?: string;
- detailAddress?: string;
+ detail?: string;
phone?: string;
};
@@ -22,7 +24,7 @@ const AddressAdd = () => {
setValue,
formState: { errors },
} = useForm({ mode: 'onChange' });
-
+ const mutation = useAddAdress();
// state
const [checked, setChecked] = useState(false);
@@ -42,82 +44,106 @@ const AddressAdd = () => {
return 'success';
};
+ const onSubmit = async (data: FormData) => {
+ if (!data.addressName || !data.name || !data.phone || !data.detail)
+ window.alert('아직 입력하지 않은 정보가 있습니다.');
+ if (data.addressName && data.name && data.phone && data.address && data.detail) {
+ const postData = {
+ addressName: data.addressName,
+ address: data.address,
+ detail: data.detail,
+ zipCode: '30751',
+ isDefault: checked,
+ id: 10,
+ };
+ try {
+ await mutation.mutateAsync(postData);
+ setTimeout(() => router.push('/setting/addressAdmin'), 0);
+ } catch (error) {
+ console.log(error);
+ window.alert(error.response?.data.message);
+ }
+ }
+ };
+
return (
-
-
-
-
-
);
};
diff --git a/src/pages/setting/addressAdmin.tsx b/src/pages/setting/addressAdmin.tsx
index ae5d668..2457649 100644
--- a/src/pages/setting/addressAdmin.tsx
+++ b/src/pages/setting/addressAdmin.tsx
@@ -10,6 +10,7 @@ const AddressAdmin = () => {
const onMoveAddressAdd = () => {
router.push('/setting/addressAdd');
};
+
return (
<>
diff --git a/src/pages/setting/changeInfo.tsx b/src/pages/setting/changeInfo.tsx
index 45821ac..15ffc64 100644
--- a/src/pages/setting/changeInfo.tsx
+++ b/src/pages/setting/changeInfo.tsx
@@ -1,9 +1,12 @@
import { css, Theme } from '@emotion/react';
import { useRouter } from 'next/router';
+import { useEffect, useState } from 'react';
+
import { useForm, DeepMap, FieldError } from 'react-hook-form';
import Button from 'src/components/common/Button';
import Input from 'src/components/common/Input';
import TopBar from 'src/components/common/layout/TopBar';
+import { useUserDataMutation } from 'src/modules/auth';
type FormData = {
email?: string;
@@ -21,6 +24,17 @@ const ChangeInfo = () => {
formState: { errors },
} = useForm
({ mode: 'onChange' });
const router = useRouter();
+ const mutation = useUserDataMutation();
+ const [info, setInfo] = useState({ email: '', authKey: '' });
+
+ const getUserData = async () => {
+ try {
+ const result = await mutation.mutateAsync({ id: 10 });
+ setInfo(result);
+ } catch (error) {
+ console.error(error);
+ }
+ };
const onValid = (name: keyof DeepMap) => {
if (errors[name]) {
@@ -33,6 +47,15 @@ const ChangeInfo = () => {
router.push('/setting/changePw');
};
+ useEffect(() => {
+ setValue('nickname', info.authKey);
+ setValue('email', info.email);
+ setValue('phone', info.email);
+ }, [info]);
+ useEffect(() => {
+ getUserData();
+ }, []);
+
return (
<>
@@ -44,7 +67,7 @@ const ChangeInfo = () => {
setValue={setValue}
register={register}
style={inputCss()}
- placeholder="info@marketuniverse.co.kr"
+ placeholder={info.email}
/>
{/* 닉네임 */}
diff --git a/src/pages/setting/index.tsx b/src/pages/setting/index.tsx
index 9059ed2..86f0dd1 100644
--- a/src/pages/setting/index.tsx
+++ b/src/pages/setting/index.tsx
@@ -1,11 +1,14 @@
import { css } from '@emotion/react';
import TopBar from 'src/components/common/layout/TopBar';
import SideBarItem from 'src/components/common/layout/SideBarItem';
-import { useCallback } from 'react';
+import { useCallback, useEffect, useState } from 'react';
import { useRouter } from 'next/router';
+import { useUserDataMutation } from 'src/modules/auth';
const SettingIndex = () => {
const router = useRouter();
+ const mutation = useUserDataMutation();
+ const [info, setInfo] = useState({ authKey: '', email: '' });
// 회원정보 이동
const onChangeInfo = useCallback(() => {
router.push('/setting/changeInfo');
@@ -14,6 +17,21 @@ const SettingIndex = () => {
const onAddressAdmin = useCallback(() => {
router.push('/setting/addressAdmin');
}, [router]);
+
+ const getUserData = async () => {
+ try {
+ const result = await mutation.mutateAsync({ id: 10 });
+ console.log(result);
+ // setInfo({ authKey: result.authKey, email: result.email });
+ } catch (error) {
+ console.error(error);
+ }
+ };
+
+ useEffect(() => {
+ getUserData();
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, []);
return (
{/* 헤더 */}
@@ -48,7 +66,7 @@ const SettingIndex = () => {
`
}
>
- 부여번호
+ {info.authKey}
@@ -57,7 +75,7 @@ const SettingIndex = () => {
`
}
>
- info@marketuniverse.co.kr
+ {info.email}