Skip to content

Commit

Permalink
feat: add expiredDateTimer nudge
Browse files Browse the repository at this point in the history
  • Loading branch information
ooooorobo committed Nov 9, 2024
1 parent c378ac5 commit 56324c9
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/pages/shared_profile/SharedProfilePage.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
flex-direction: column;
overflow: hidden;
height: 100%;
width: 100%;
}

.Header {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/shared_profile/SharedProfilePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const SharedProfilePage = ({ expiredDate }: Props) => {
)}
<ScrollView rootClassName={styles.Body}>
<ImageLayout urls={urls} />
<ExpiredDateTimer expiredDate={expiredDate} />
<ExpiredDateTimer expiredDate={expiredDate} type={inView ? 'BOX' : 'NUDGE'} />
<h1 className={styles.Name} ref={ref}>
{profile.name}({t(profile.gender)}, {age})
</h1>
Expand Down
34 changes: 34 additions & 0 deletions src/pages/shared_profile/components/ExpiredDateTimer.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,37 @@
font-size: 16px;
font-weight: 600;
}

.Nudge {
z-index: 1;
position: fixed;
top: 56px;
left: 50%;
transform: translateX(-50%);
width: max-content;

background-color: var(--color-neutral-70);
border-radius: 48px;

display: flex;
padding: 8px;
gap: 16px;
align-items: center;

& .Timer {
width: 100%;
gap: 8px;
padding-left: 8px;
}

& span {
font-size: 14px;
color: var(--color-neutral-0);
}

& .TimerText {
width: 62px;
color: var(--color-primary);
font-size: 14px;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ type Story = StoryObj<typeof ExpiredDateTimer>;
export const Default: Story = {
args: {
expiredDate: dayjs().add(1, 'day').toDate(),
type: 'NUDGE',
},
};
44 changes: 33 additions & 11 deletions src/pages/shared_profile/components/ExpiredDateTimer.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { useEffect, useState } from 'react';
import { Timer } from 'src/shared/ui/icons';
import { Close, Timer } from 'src/shared/ui/icons';
import { Theme } from 'src/shared/styles/constants';
import dayjs from 'dayjs';
import styles from './ExpiredDateTimer.module.css';
import { IconButton } from 'src/shared/ui/IconButton/IconButton';

const refineNumber = (n: number) => Math.floor(n).toString().padStart(2, '0');
const getDiffText = (expiredDate: Date) => {
const diff = dayjs(expiredDate).diff(dayjs(), 'second');
return `${Math.floor(diff / (60 * 60))}:${Math.floor((diff % (60 * 60)) / 60)}:${Math.floor(diff % 60)}`;
return `${refineNumber(diff / (60 * 60))}:${refineNumber((diff % (60 * 60)) / 60)}:${refineNumber(diff % 60)}`;
};

export const ExpiredDateTimer = ({ expiredDate }: { expiredDate: Date }) => {
export const ExpiredDateTimer = ({ expiredDate, type = 'BOX' }: { expiredDate: Date; type: 'BOX' | 'NUDGE' }) => {
const [timerText, setTimerText] = useState(() => getDiffText(expiredDate));

useEffect(() => {
Expand All @@ -19,13 +21,33 @@ export const ExpiredDateTimer = ({ expiredDate }: { expiredDate: Date }) => {
return () => clearInterval(timer);
}, []);

return (
<div className={styles.Box}>
<span className={styles.Description}>이 시간동안 정보를 확인할 수 있어요!</span>
<div className={styles.Timer}>
<Timer color={Theme.color.primary} />
<span className={styles.TimerText}>{timerText}</span>
const [showNudge, setShowNudge] = useState(true);

if (type === 'BOX') {
return (
<div className={styles.Box}>
<span className={styles.Description}>이 시간동안 정보를 확인할 수 있어요!</span>
<div className={styles.Timer}>
<Timer color={Theme.color.primary} />
<span className={styles.TimerText}>{timerText}</span>
</div>
</div>
</div>
);
);
}

if (type === 'NUDGE') {
return (
showNudge && (
<div className={styles.Nudge}>
<div className={styles.Timer}>
<span>정보 확인 가능 시간</span>
<span className={styles.TimerText}>{timerText}</span>
</div>
<IconButton onClick={() => setShowNudge(false)}>
<Close color={Theme.color.neutral10} />
</IconButton>
</div>
)
);
}
};
1 change: 1 addition & 0 deletions src/shared/styles/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const Theme = {
neutral30: '#cdcace',
neutral20: '#ebeaeb',
neutral10: '#f5f5f5',
neutral0: '#fff',
kakao: '#FFE812',
},
} as const;
4 changes: 4 additions & 0 deletions src/shared/ui/Button/Button.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,8 @@

.Center {
flex-grow: 1;

display: flex;
justify-content: center;
align-items: center;
}
2 changes: 1 addition & 1 deletion src/shared/ui/ImageLayout/ImageLayout.module.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

.Carousel {
width: 100%;
max-width: 480px;
max-width: min(480px, 100vw);
height: 256px;
background-color: var(--color-neutral-10);

Expand Down

0 comments on commit 56324c9

Please sign in to comment.