-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainCard.tsx
More file actions
159 lines (148 loc) · 4.28 KB
/
MainCard.tsx
File metadata and controls
159 lines (148 loc) · 4.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import { Progress, Button } from '@pinback/design-system/ui';
import { useState, useEffect } from 'react';
import { motion, AnimatePresence } from 'framer-motion';
import StoryStep from './step/StoryStep';
import AlarmStep from './step/AlarmStep';
import MacStep from './step/MacStep';
import FinalStep from './step/FinalStep';
import { cva } from 'class-variance-authority';
import { usePostSignUp } from '@shared/apis/queries';
const stepProgress = [{ progress: 30 }, { progress: 60 }, { progress: 100 }];
import { AlarmsType } from '@constants/alarms';
import { normalizeTime } from '@pages/onBoarding/utils/formatRemindTime';
const variants = {
slideIn: (direction: number) => ({
x: direction > 0 ? 200 : -200,
opacity: 0,
}),
slideCenter: { x: 0, opacity: 1 },
slideOut: (direction: number) => ({
x: direction > 0 ? -200 : 200,
opacity: 0,
}),
};
const CardStyle = cva(
'bg-white-bg flex h-[54.8rem] w-[63.2rem] flex-col items-center justify-between rounded-[2.4rem] pt-[3.2rem]',
{
variants: {
overflow: {
true: 'overflow-visible',
false: 'overflow-hidden',
},
},
defaultVariants: { overflow: false },
}
);
const MainCard = () => {
const [step, setStep] = useState(0);
const [direction, setDirection] = useState(0);
const [alarmSelected, setAlarmSelected] = useState<1 | 2 | 3>(1);
const [isMac, setIsMac] = useState(false);
// api 구간
const {mutate:postSignData} = usePostSignUp();
useEffect(() => {
const ua = navigator.userAgent.toLowerCase();
if (ua.includes('mac os') || ua.includes('iphone') || ua.includes('ipad')) {
setIsMac(true);
}
}, []);
const renderStep = () => {
switch (step) {
case 0:
case 1:
case 2:
return <StoryStep step={step as 0 | 1 | 2} />;
case 3:
return <AlarmStep selected={alarmSelected} setSelected={setAlarmSelected} />;
case 4:
if (isMac) return <MacStep />;
return <FinalStep />;
case 5:
if (isMac) return <FinalStep />;
return null;
default:
return <FinalStep />;
}
};
const [remindTime, setRemindTime] = useState('09:00');
const nextStep = () => {
console.log(step)
if (step === 3) {
// 이거 이후에 api 붙일 자리 표시임!
}
if (step < 5) {
setDirection(1);
setStep((prev) => prev + 1);
} else if (step === 5) {
const raw = AlarmsType[alarmSelected - 1].time;
setRemindTime(normalizeTime(raw));
postSignData({
"email": "tesdfdfsst@gmail.com",
"remindDefault": remindTime,
"fcmToken": "adlfdjlajlkadfsjlkfdsdfsdfsdfsdfsa"
},
{
onSuccess:()=>{
window.location.href = '/';
}
}
)
}
};
const prevStep = () => {
if (step > 0) {
setDirection(-1);
setStep((prev) => prev - 1);
}
};
return (
<div className={CardStyle({ overflow: step === 3 && alarmSelected === 3 })}>
{step < 3 && (
<Progress
value={stepProgress[step].progress}
variant="profile"
className="w-[15.6rem]"
/>
)}
<div className="relative flex h-full w-full items-center justify-center">
<AnimatePresence custom={direction} mode="wait">
<motion.div
key={step}
custom={direction}
variants={variants}
initial="slideIn"
animate="slideCenter"
exit="slideOut"
transition={{ duration: 0.4 }}
className="flex h-full flex-col items-center"
>
{renderStep()}
</motion.div>
</AnimatePresence>
</div>
<div className="mb-[4.8rem] mt-[1.2rem] flex w-full justify-between px-[3.2rem]">
{step < 4 && (
<Button
variant="primary"
size="medium"
isDisabled={step === 0}
className="w-[4.8rem]"
onClick={prevStep}
>
이전
</Button>
)}
<Button
variant="primary"
size="medium"
isDisabled={step === 6}
className="ml-auto w-[4.8rem]"
onClick={nextStep}
>
다음
</Button>
</div>
</div>
);
};
export default MainCard;