Skip to content

Commit

Permalink
feat(bottle): open web view on profile edit
Browse files Browse the repository at this point in the history
  • Loading branch information
stakbucks committed Sep 15, 2024
1 parent 460c74c commit 7601b40
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 19 deletions.
15 changes: 14 additions & 1 deletion apps/bottle/src/app/profile/edit/BasicInformation.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
'use client';

import { Profile } from '@/components/profile';
import { AppBridgeMessageType, useAppBridge } from '@/features/app-bridge';
import { buildWebViewUrl } from '@/features/app-bridge/utils';
import { useMyInformationQuery } from '@/store/query/useMyInformation';
import { spacings } from '@bottlesteam/ui';

export function BasicInformation() {
const { send } = useAppBridge();
const {
data: { imageUrl, age, userName },
} = useMyInformationQuery();

return <Profile image={imageUrl} name={userName} age={age} style={{ marginTop: spacings.xxl }} />;
return (
<Profile
image={imageUrl}
name={userName}
age={age}
style={{ marginTop: spacings.xxl }}
onEditClick={() => {
send({ type: AppBridgeMessageType.OPEN_WEB_VIEW, payload: { href: buildWebViewUrl('/profile/edit/image') } });
}}
/>
);
}
35 changes: 22 additions & 13 deletions apps/bottle/src/app/profile/edit/ProfileArea.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
'use client';

import { Card } from '@/components/card';
import { AppBridgeMessageType, useAppBridge } from '@/features/app-bridge';
import { buildWebViewUrl } from '@/features/app-bridge/utils';
import { useMyInformationQuery } from '@/store/query/useMyInformation';
import { Asset, Paragraph, spacings } from '@bottlesteam/ui';
import { useMemo } from 'react';
import { profileItemLeftStyle, profileItemStyle } from './profileEditStyle.css';

export function ProfileArea() {
const { send } = useAppBridge();
const {
data: {
profileSelect: {
Expand All @@ -23,18 +26,18 @@ export function ProfileArea() {
},
} = useMyInformationQuery();

const profileItems = useMemo(
const editProfileItems = useMemo(
() => [
{ title: '카카오톡 아이디', description: 'dhassidu11', onRightArrowClick: () => {} },
{ title: '카카오톡 아이디', description: 'dhassidu11', endpoint: '/profile/edit/kakaoId' },
{
title: '나의 성격',
description: mbti,
onRightArrowClick: () => {},
endpoint: '/profile/edit/mbti',
},
{
title: '나를 표현하는 키워드',
description: keyword.join(', '),
onRightArrowClick: () => {},
endpoint: '/profile/edit/keyword',
},
{
title: '푹 빠진 취미',
Expand All @@ -44,37 +47,37 @@ export function ProfileArea() {
...Object.values(entertainment),
...Object.values(etc),
].join(', '),
onRightArrowClick: () => {},
endpoint: '/profile/edit/interest',
},
{
title: '직업 · 직무',
description: job,
onRightArrowClick: () => {},
endpoint: '/profile/edit/job',
},
{
title: '키',
description: `${height}cm`,
onRightArrowClick: () => {},
endpoint: '/profile/edit/height',
},
{
title: '흡연 스타일',
description: smoking,
onRightArrowClick: () => {},
endpoint: '/profile/edit/smoking',
},
{
title: '음주 스타일',
description: alcohol,
onRightArrowClick: () => {},
endpoint: '/profile/edit/alcohol',
},
{
title: '종교',
description: religion,
onRightArrowClick: () => {},
endpoint: '/profile/edit/religion',
},
{
title: '지역',
description: city,
onRightArrowClick: () => {},
endpoint: '/profile/edit/region',
},
],
[mbti, keyword, culture, sports, entertainment, job, height, smoking, alcohol, religion, city, etc]
Expand All @@ -83,8 +86,14 @@ export function ProfileArea() {
return (
<Card asChild style={{ marginTop: spacings.sm, marginBottom: spacings.xl }}>
<ul>
{profileItems.map(({ title, description }) => (
<li key={title} className={profileItemStyle}>
{editProfileItems.map(({ title, description, endpoint }) => (
<li
key={title}
className={profileItemStyle}
onClick={() => {
send({ type: AppBridgeMessageType.OPEN_WEB_VIEW, payload: { href: buildWebViewUrl(endpoint) } });
}}
>
<div className={profileItemLeftStyle}>
<Paragraph color="neutral900" typography="st2">
{title}
Expand Down
2 changes: 1 addition & 1 deletion apps/bottle/src/components/profile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function Profile({ image, name, age, onEditClick, ...rest }: ProfileProps
return (
<div className={wrapperStyle} {...rest}>
{onEditClick != null ? (
<div className={avatarAreaStyle}>
<div onClick={onEditClick} className={avatarAreaStyle}>
<Avatar src={image} size="lg" />
<button className={editButtonStyle}>
<Asset type="icon-pencil" />
Expand Down
9 changes: 5 additions & 4 deletions apps/bottle/src/components/profile/profileStyle.css.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { spacings } from '@bottlesteam/ui';
import { colors, spacings } from '@bottlesteam/ui';
import { style } from '@vanilla-extract/css';

export const wrapperStyle = style({
Expand All @@ -19,11 +19,12 @@ export const avatarAreaStyle = style({
export const editButtonStyle = style({
width: '24px',
height: '24px',
borderRadius: '50%',
border: `1px solid ${colors.neutral300}`,
position: 'absolute',
bottom: 0,
right: 5,
background: 'none',
border: 'none',
right: -5,
backgroundColor: colors.white100,
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
Expand Down
6 changes: 6 additions & 0 deletions apps/bottle/src/features/app-bridge/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getClientSideTokens } from '../server/clientSideTokens';
import { AppBridgeMessage, ToastMessage } from './interface';

export function isToastMessage(message: AppBridgeMessage): message is ToastMessage {
Expand All @@ -7,3 +8,8 @@ export function isToastMessage(message: AppBridgeMessage): message is ToastMessa
export function hasPayload(message: AppBridgeMessage) {
return 'payload' in message;
}

export function buildWebViewUrl(endpoint: string) {
const { accessToken, refreshToken } = getClientSideTokens();
return `https://bottle.bottles.asia/${endpoint}?accessToken=${accessToken}&refreshToken=${refreshToken}`;
}

0 comments on commit 7601b40

Please sign in to comment.