Skip to content

Commit 9e4bc44

Browse files
committed
feat: sendTextMessage 관련 수정 (#develop)
1 parent 6ed9106 commit 9e4bc44

File tree

7 files changed

+5096
-2
lines changed

7 files changed

+5096
-2
lines changed

services/ahhachul.com/src/components/domain/complaint/postDetail/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export { default as ComplaintCommentList } from './commentList/ComplaintCommentL
44
export { default as ComplaintDetailHeaderActions } from './headerActions/ComplaintHeaderActions.component';
55
export { default as ComplaintDetailSkeleton } from './skeleton/ComplaintDetail.skeleton';
66
export { default as ComplaintErrorPage } from './error/ComplaintErrorPage.component';
7+
export { default as SendComplaintMessage } from './sendMessage/SendMessage.component';
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import { UiComponent } from '@/components';
2+
import { getSubwayComplaintCallNumber, subwayLineOptions } from '@/constants';
3+
import { useNativeBridge } from '@/contexts';
4+
import { useUser } from '@/hooks/domain';
5+
import type { ComplaintType, ShortComplaintType } from '@/types/complaint';
6+
import { getSharePageURL } from '@/utils/share';
7+
8+
const formatComplaintTypeToKoSentence = (complaintType?: ComplaintType) => {
9+
if (!complaintType) return;
10+
11+
switch (complaintType) {
12+
case 'ENVIRONMENTAL_COMPLAINT':
13+
return '환경 민원이 발생했어요.';
14+
case 'TEMPERATURE_CONTROL':
15+
return '온도조절 민원이 발생했어요.';
16+
case 'DISORDER':
17+
return '질서저해 민원이 발생했어요.';
18+
case 'ANNOUNCEMENT':
19+
return '안내방송 민원이 발생했어요.';
20+
case 'EMERGENCY_PATIENT':
21+
return '응급환자 민원이 발생했어요.';
22+
case 'VIOLENCE':
23+
return '폭력 민원이 발생했어요.';
24+
case 'SEXUAL_HARASSMENT':
25+
return '성추행 민원이 발생했어요.';
26+
default:
27+
return '민원이 발생했어요.';
28+
}
29+
};
30+
31+
const formatComplaintShortContentToKoSentence = (shortComplaintType?: ShortComplaintType) => {
32+
if (!shortComplaintType) return;
33+
34+
switch (shortComplaintType) {
35+
case 'WASTE':
36+
return '오물이 있어요!';
37+
case 'VOMIT':
38+
return '토사물이 있어요!';
39+
case 'VENTILATION_REQUEST':
40+
return '안좋은 냄새가 나요, 환기 좀 부탁드려요!';
41+
case 'NOISY':
42+
return '안내방송이 너무 커서 시끄러워요!';
43+
case 'NOT_HEARD':
44+
return '안내방송이 너무 작아서 안들려요!';
45+
case 'TOO_HOT':
46+
return '너무 더워요! 온도 좀 낮춰주세요.';
47+
case 'TOO_COLD':
48+
return '너무 추워요! 온도 좀 높여주세요.';
49+
case 'MOBILE_VENDOR':
50+
return '이동상인이 물건을 팔아요!';
51+
case 'DRUNK':
52+
return '취객이 돌아다녀요!';
53+
case 'HOMELESS':
54+
return '지하철에서 노숙을 하고 계세요!';
55+
case 'BEGGING':
56+
return '지하철에서 구걸하고 계신 분이 있어요!';
57+
case 'RELIGIOUS_ACTIVITY':
58+
return '지하철에서 종교행위하고 계신 분이 있어요!';
59+
case 'SELF':
60+
return '본인이 환자입니다.';
61+
case 'WITNESS':
62+
return '본인은 목격자입니다.';
63+
case 'VICTIM':
64+
return '본인이 피해자입니다.';
65+
default:
66+
return '민원이 발생했어요';
67+
}
68+
};
69+
70+
type Props = {
71+
id: number;
72+
complaintType: ComplaintType;
73+
shortContentType: ShortComplaintType;
74+
subwayLineId: number;
75+
createdBy: number;
76+
};
77+
78+
export default function SendComplaintMessage({
79+
id,
80+
complaintType,
81+
shortContentType,
82+
subwayLineId,
83+
createdBy,
84+
}: Props) {
85+
const { user } = useUser();
86+
const { bridge, isBridgeInitialized } = useNativeBridge();
87+
88+
const isAuthor = user?.memberId === createdBy;
89+
const lineName = subwayLineOptions[subwayLineId.toString() as keyof typeof subwayLineOptions];
90+
const targetUrl = getSharePageURL('ComplaintDetailPage');
91+
const url = `${targetUrl}/${id}`;
92+
93+
const messageContent = [
94+
`${lineName} ${formatComplaintTypeToKoSentence(complaintType)}`,
95+
formatComplaintShortContentToKoSentence(shortContentType),
96+
'',
97+
'아하철에서 자세한 내용을 확인해주세요.',
98+
'',
99+
url,
100+
].join('\n');
101+
102+
const handleClick = () => {
103+
if (isBridgeInitialized) {
104+
const phoneNumber = getSubwayComplaintCallNumber(+subwayLineId);
105+
bridge.send.sendTextMessage(phoneNumber, messageContent);
106+
}
107+
};
108+
109+
if (!isAuthor) return null;
110+
111+
return <UiComponent.FloatButton onClick={handleClick}>즉시 민원 보내기</UiComponent.FloatButton>;
112+
}

services/ahhachul.com/src/components/domain/complaint/postDetail/template/ComplaintDetail.component.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ const ComplaintDetail = ({ id }: ComplaintDetailProps) => {
1616

1717
return (
1818
<>
19+
<ComplaintComponent.SendComplaintMessage
20+
id={post.id}
21+
createdBy={+post.createdBy}
22+
subwayLineId={post.subwayLineId}
23+
complaintType={post.complaintType}
24+
shortContentType={post.shortContentType}
25+
/>
1926
<ComplaintComponent.ComplaintDetailHeaderActions id={id} createdBy={+post.createdBy} />
2027

2128
<S.ArticleWrapper>

services/ahhachul.com/src/constants/complaint.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,19 @@ export const complaintTypeOptions: Record<ComplaintType, string> = {
119119
VIOLENCE: '폭력',
120120
SEXUAL_HARASSMENT: '성추행',
121121
};
122+
123+
export const getSubwayComplaintCallNumber = (subwayLineId: number) => {
124+
if (subwayLineId === 9) {
125+
return '1544-4009';
126+
}
127+
128+
if (subwayLineId === 18) {
129+
return '031-8018-7777';
130+
}
131+
132+
if (subwayLineId === 13 || subwayLineId === 11 || subwayLineId === 16) {
133+
return '1544-7769';
134+
}
135+
136+
return '1577-1234';
137+
};

services/ahhachul.com/src/contexts/native-bridge.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,20 @@ export const NativeBridge: React.FC<NativeBridgeProps> = ({ children }) => {
3030
}),
3131
);
3232
},
33-
sendTextMessage: (number: string) => {
33+
sendTextMessage: (number: string, message?: string) => {
34+
const processedMessage = message
35+
? message
36+
.replace(/\n/g, '%0A')
37+
.replace(/[&]/g, '%26')
38+
.replace(/[+]/g, '%2B')
39+
.replace(/\s/g, '%20')
40+
: '';
41+
3442
window.ReactNativeWebView?.postMessage(
3543
JSON.stringify({
3644
name: 'sendTextMessage',
3745
number,
46+
message: processedMessage,
3847
}),
3948
);
4049
},

services/ahhachul.com/src/types/nativeBridge.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export type NativeBridgeType = {
1010
share: (link: string) => void;
1111
callPhone: (number: string) => void;
1212
openExternalLink: (link: string) => void;
13-
sendTextMessage: (number: string) => void;
13+
sendTextMessage: (number: string, message?: string) => void;
1414
};
1515
receive: {
1616
deviceInfo: () => Promise<{

0 commit comments

Comments
 (0)