Skip to content

Commit

Permalink
Merge pull request #146 from Dindb-dong/feat/132/ServicePage
Browse files Browse the repository at this point in the history
#132 fix: minor fixes, service api(ing)
  • Loading branch information
miikii41 authored Nov 5, 2024
2 parents b3dbdb6 + bb4c88b commit caaef37
Show file tree
Hide file tree
Showing 12 changed files with 234 additions and 128 deletions.
12 changes: 6 additions & 6 deletions App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ const CustomTab = ({ state, descriptors, navigation }: BottomTabBarProps) => {
});
else navigation.navigate(route.name, { id: undefined });
} else if (route.name == '주문관리') {
if (isFocused)
navigation.reset({
routes: [{ name: route.name, params: { id: undefined } }],
});
else navigation.navigate(route.name, { id: undefined });
} else if (route.name == '마이페이지') {
if (isFocused)
navigation.reset({
routes: [{ name: route.name, params: { id: undefined } }],
});
else navigation.navigate(route.name, { id: undefined });
} else if (route.name == '마이페이지') {
if (isFocused)
navigation.reset({
routes: [{ name: route.name, params: { id: undefined } }],
Expand Down
46 changes: 29 additions & 17 deletions src/components/Auth/BasicForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import DownArrow from '../../assets/common/DownArrow.svg';
import LeftArrow from '../../assets/common/Arrow.svg';
import Logo from '../../assets/common/Logo.svg';
import { FormProps } from './SignIn';
import { useState } from 'react';
import { useEffect, useState } from 'react';
import InputBox from '../../common/InputBox';
import InputView from '../../common/InputView';
import BottomButton from '../../common/BottomButton';
Expand Down Expand Up @@ -104,18 +104,18 @@ export default function BasicForm({ navigation, route }: FormProps) {
const is_reformer = route.params?.is_reformer ?? false;
const { width, height } = Dimensions.get('window');
const [form, setForm] = useState<BasicFormProps2>({
mail: '',
domain: undefined,
password: '',
nickname: '',
agreement: {
mail: route.params?.mail || '',
domain: route.params?.domain || undefined,
password: route.params?.password || '',
nickname: route.params?.nickname || '',
agreement: route.params?.agreement || {
a: false,
b: false,
c: false,
d: false,
},
introduce: '',
profile_image: undefined,
introduce: route.params?.introduce || '',
profile_image: route.params?.profile_image || undefined,
});
const [checkPw, setCheckPw] = useState('');
const [isModalVisible, setModalVisible] = useState(false); // 리폼러 가입 모달
Expand All @@ -125,30 +125,41 @@ export default function BasicForm({ navigation, route }: FormProps) {
'^(?=.*[a-zA-Z])(?=.*[!@#$%^*+=-])(?=.*[0-9]).{8,15}$',
);

useEffect(() => {
if (route.params?.form) {
setForm(route.params.form)
}
}, [route.params?.form]);

const handleLogin = async () => { // 로그인 API 사용해서 토큰 발급
const params = {
email: form.mail + '@' + form.domain,
password: form.password
}
const response = await request.post(`/api/user/login`, params);
await processLoginResponse2( // userRole 설정 함수
response
);
if (form.mail === '' || form.password === '') {
Alert.alert('이메일과 비밀번호를 모두 입력해주세요.')
} else {
const response = await request.post(`/api/user/login`, params);
await processLoginResponse2( // userRole 설정 함수
response
);
}
};

const passwordValidation = async () => {
if (form.agreement.a === false || form.agreement.b === false || form.agreement.c === false ||
form.domain === undefined || form.mail === '') {
const form_ = { ...form }
if (form_.agreement.a === false || form_.agreement.b === false || form_.agreement.c === false ||
form_.domain === undefined || form_.mail === '') {
Alert.alert('필수 사항들을 모두 입력해주세요.')
} else if (!form.domain.includes('.')) {
} else if (!form_.domain.includes('.')) {
Alert.alert('올바른 이메일 형식이 아닙니다.')
} else { // 누락된거 없을 때
if (passwordRegExp.exec(form.password)) {
if (passwordRegExp.exec(form_.password)) {
if (is_reformer === true) { // 리폼러의 경우
await handleSubmit(); // 일단 회원가입 하고,
handleLogin(); // 토큰 발급 로직
} else { // 업씨러의 경우
navigation.navigate('Upcyer', { form })
navigation.navigate('Upcyer', { form_ })
}
} else {
Alert.alert('비밀번호가 올바르지 않습니다.');
Expand Down Expand Up @@ -367,6 +378,7 @@ export default function BasicForm({ navigation, route }: FormProps) {
value="다음"
pressed={false}
onPress={() => {
console.log(form);
passwordValidation();
}}
// onPress={() => handleNext()} // 이건 임시.
Expand Down
40 changes: 20 additions & 20 deletions src/components/Auth/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export async function processLoginResponse( // 통상 로그인시 호출 함수
setUser: (user: UserType) => void // setUser 전달
) {
// const navigation = useNavigation<StackNavigationProp<MyPageProps>>();
if (response?.status == 200) {
if (response?.status === 200) {
const accessToken = await response.data.access;
const refreshToken = await response.data.refresh;
setAccessToken(accessToken);
Expand All @@ -124,14 +124,10 @@ export async function processLoginResponse( // 통상 로그인시 호출 함수
navigate(); // 인자로 전달받은 네비게이팅 수행
console.log('로그인 성공');

} else if (response.status == 400) {
Alert.alert(
response.data.extra.fields !== undefined
? response.data.extra.fields.detail
: response.data.message,
);
} else {
Alert.alert('예상치 못한 오류가 발생하였습니다.');
} else if (response.status === 400) {
Alert.alert('비밀번호가 틀렸습니다.');
} else if (response.status === 404) {
Alert.alert('이메일을 찾을 수 없습니다.');
}
};

Expand All @@ -143,17 +139,21 @@ export default function Login({ navigation, route }: LoginProps) {
const request = Request();

const handleLogin = async () => { // 로그인 함수
const response = await request.post(`/api/user/login`, form);
processLoginResponse(
response,
() => {
const parentNav = navigation.getParent();
if (parentNav != undefined) parentNav.goBack();
else navigation.navigate('Home');
},
setLogin,
setUser // setUser 전달,
);
if (form.email === '' || form.password === '') {
Alert.alert('이메일과 비밀번호를 모두 입력해주세요.')
} else {
const response = await request.post(`/api/user/login`, form);
processLoginResponse(
response,
() => {
const parentNav = navigation.getParent();
if (parentNav != undefined) parentNav.goBack();
else navigation.navigate('Home');
},
setLogin,
setUser // setUser 전달,
);
}
};

return (
Expand Down
9 changes: 9 additions & 0 deletions src/components/Auth/Reformer/Profile/Service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import {
createStackNavigator,
} from '@react-navigation/stack';
import styled from 'styled-components/native';
import DetailScreenHeader from '../../../Home/components/DetailScreenHeader.tsx';

// 리폼러 입장에서 보는 마이페이지!
// Stack Navigator 생성
const Stack = createStackNavigator();

Expand Down Expand Up @@ -59,6 +61,13 @@ export const ProfileSection = ({

return (
<View>
<DetailScreenHeader
title=''
onPressLeft={() => { }}
onPressRight={() => navigation.navigate('FixMyPage', { userInfo })}
leftButton='CustomBack'
rightButton='Fix'
/>
{/* 배경 이미지와 프로필 사진 추가 */}
<ImageBackground
style={{ width: '100%', height: 200 }}
Expand Down
5 changes: 3 additions & 2 deletions src/components/Auth/SignIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Reformer from './Reformer/Reformer';
import BasicForm, { BasicFormProps2 } from './BasicForm';
import ReformFormSubmit from './Reformer/ReformFormSubmit';
import { UpcyFormProfile } from '../Auth/Upcyer/Upcyer'
import { BottomSheetModalStackBehavior } from '@gorhom/bottom-sheet/lib/typescript/components/bottomSheetModal';

export interface FormProps {
route: any;
Expand All @@ -23,9 +24,9 @@ export type SignInParams = {
Login: undefined;
Signup: undefined;
Reformer: undefined;
Basic: undefined;
Basic: { form?: any | undefined };
ReformSubmit: undefined;
Upcyer: { form: BasicFormProps2 };
Upcyer: { form: any };
};

export default function SignIn() { // 스택 네비게이터 설정
Expand Down
41 changes: 33 additions & 8 deletions src/components/Auth/Upcyer/Upcyer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,23 @@ import DetailScreenHeader from '../../Home/components/DetailScreenHeader';
import { getAccessToken } from '../../../common/storage';
import Request from '../../../common/requests';
import { BasicFormProps2 } from '../BasicForm';
import { StackNavigationProp } from '@react-navigation/stack';
import { StackNavigationProp, StackScreenProps } from '@react-navigation/stack';
import { SignInParams } from '../SignIn';

interface UpcyerProps2 extends UpcyerProps {
navigation: any;
route: any;
}

interface UpcyerProps {
form: BasicFormProps2;
setForm: Dispatch<SetStateAction<BasicFormProps2>>;
}

type UpcyerPageProps = StackScreenProps<SignInParams, 'Upcyer'>;

function ProfilePic({ form, setForm }: UpcyerProps) {
const [photo, setPhoto] = useState(form.profile_image);
const [photo, setPhoto] = useState(form?.profile_image);
const [handleAddButtonPress, handleImagePress] = useImagePicker(setPhoto);

useEffect(() => {
Expand Down Expand Up @@ -88,14 +95,32 @@ function ProfilePic({ form, setForm }: UpcyerProps) {
);
}

export const UpcyFormProfile = (navigation: any, route: any) => {
export const UpcyFormProfile = ({ navigation, route }: UpcyerPageProps) => {
const { width } = Dimensions.get('screen');
const [isModalVisible, setModalVisible] = useState(false);
const [nickname, setNickname] = useState('');
const [introduce, setIntroduce] = useState('');
const request = Request();
const { form } = route.params;
const [form_, setForm] = useState<BasicFormProps2>(form);
const form = route.params.form;
const [form_, setForm] = useState<BasicFormProps2>({
mail: form?.mail || '',
domain: form?.domain || '',
password: form?.password || '',
nickname: form?.nickname || '',
agreement: form?.agreement,
introduce: form?.introduce || '',
profile_image: form?.profile_image || undefined,
});

useEffect(() => {
form.agreement = form_.agreement;
form.domain = form_.domain;
form.introduce = form_.introduce;
form.mail = form_.mail;
form.nickname = form_.nickname;
form.password = form_.password;
form.profile_image = form_.profile_image;
}, [form_])

const handleSubmit = async () => {
const params = {
Expand Down Expand Up @@ -153,7 +178,7 @@ export const UpcyFormProfile = (navigation: any, route: any) => {
<ProfilePic form={form_} setForm={setForm} />
<InputView
title="닉네임"
value={form_.nickname}
value={form_?.nickname}
setValue={(value) =>
setForm(prev => {
return { ...prev, nickname: value };
Expand All @@ -163,7 +188,7 @@ export const UpcyFormProfile = (navigation: any, route: any) => {
/>
<InputView
title="소개글"
value={form_.introduce}
value={form_?.introduce}
setValue={(value) =>
setForm(prev => {
return { ...prev, introduce: value };
Expand All @@ -172,7 +197,7 @@ export const UpcyFormProfile = (navigation: any, route: any) => {
caption={{ default: '본인을 소개하는 글을 작성해주세요' }}
long={true}
/>
<Pressable onPress={() => console.log(form_)}>
<Pressable onPress={() => console.log(form)}>
<Text>ddddddd</Text>
</Pressable>
<BottomButton
Expand Down
1 change: 1 addition & 0 deletions src/components/Home/Market/InfoPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import styled from 'styled-components/native';
import { Body14R, Body16B } from '../../../styles/GlobalText';

//TODO: ReformerProfilePage로 이름 수정
// 개별 마켓 페이지 누르면 보이는 '프로필' 탭에 있는 페이지임!
const InfoPage = () => {
const data = [
{
Expand Down
Loading

0 comments on commit caaef37

Please sign in to comment.