From 1763d2bc35a5bf33cb2c5e7f69359f46dda7c4d2 Mon Sep 17 00:00:00 2001 From: Orca1110 Date: Tue, 27 Sep 2022 21:13:40 +0900 Subject: [PATCH 1/4] :sparkles: API fcm.. not yet.. --- api/fcm/types.ts | 5 ++--- components/profile/FollowButton.tsx | 5 +++-- screens/CreateMsgScreen.tsx | 12 +++++++++++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/api/fcm/types.ts b/api/fcm/types.ts index 3993204f..210ad8bb 100644 --- a/api/fcm/types.ts +++ b/api/fcm/types.ts @@ -1,11 +1,10 @@ export interface SingleAlert { pool_user_id: number; - brand_id: number; + // brand_id: number; } export interface MultiAlert { - brand_id: number; - Message_id: number; + pool_user_id: number; } export interface FCMParams { diff --git a/components/profile/FollowButton.tsx b/components/profile/FollowButton.tsx index 3a843bcd..ec717e4f 100644 --- a/components/profile/FollowButton.tsx +++ b/components/profile/FollowButton.tsx @@ -14,7 +14,6 @@ interface Props { function FollowButton({isFollowed, poolUserId, refetch}: Props) { // const [isFollow, setIsFollow] = useState(isFollowed); - // const {mutate: sendWelcomeMessage} = useMutation(sendSingleAlarm); const {mutate: onPressFollow} = useMutation(follow, { onSuccess: () => { // setIsFollow(true); @@ -30,6 +29,7 @@ function FollowButton({isFollowed, poolUserId, refetch}: Props) { refetch(); }, }); + // const {mutate: sendWelcome} = useMutation(sendSingleAlarm); return ( @@ -38,7 +38,8 @@ function FollowButton({isFollowed, poolUserId, refetch}: Props) { onPress={ () => isFollowed ? onPressUnfollow(poolUserId) : onPressFollow(poolUserId) - // sendWelcomeMessage({pool_user_id: poolUserId, brand_id: 1}) + + // sendWelcome({pool_user_id: poolUserId}) }> {isFollowed ? '팔로잉' : '팔로우'} diff --git a/screens/CreateMsgScreen.tsx b/screens/CreateMsgScreen.tsx index 48ce9ae9..676ca166 100644 --- a/screens/CreateMsgScreen.tsx +++ b/screens/CreateMsgScreen.tsx @@ -24,6 +24,8 @@ import {getBrand} from '../api/brand'; import {launchImageLibrary} from 'react-native-image-picker'; import {createMessage} from '../api/message'; import {ImgAsset} from '../api/message/types'; +import {sendMultiAlarm} from '../api/fcm'; +import {getUser} from '../api/auth'; export interface CreateMessageProps { messageBody: string; @@ -69,18 +71,26 @@ function CreateMessageScreen() { refetchOnMount: 'always', }); + const {data: poolId} = useQuery('getUserResult', () => getUser(), { + refetchOnMount: true, + }); + const {mutate: create} = useMutation(createMessage, { onSuccess: () => { navigation.dispatch(CommonActions.goBack()); }, }); + + const {mutate: send} = useMutation(sendMultiAlarm); + const onSubmit = useCallback(() => { const formData = new FormData(); formData.append('body', form.messageBody); formData.append('messageLink', form.messageLink as string); formData.append('multipartFiles', form.messageImage as Blob); create(formData); - }, [create, form]); + send({pool_user_id: poolId?.poolUserId as number}); + }, [create, form, send]); const onChangeText = (prop: string) => (value: string) => { setForm({ From 8adf4d164b4599e6c30839be2e9a2328640e4660 Mon Sep 17 00:00:00 2001 From: Orca1110 Date: Thu, 29 Sep 2022 17:40:49 +0900 Subject: [PATCH 2/4] :sparkles: Added FCM API #315 Finally --- api/fcm/index.ts | 5 +++-- api/fcm/types.ts | 4 ++-- screens/CreateMsgScreen.tsx | 23 ++++++++++++++++++----- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/api/fcm/index.ts b/api/fcm/index.ts index fc80e54d..65ef80a7 100644 --- a/api/fcm/index.ts +++ b/api/fcm/index.ts @@ -1,5 +1,5 @@ import client from '../client'; -import {SingleAlert, MultiAlert, FCMParams} from './types'; +import {SingleAlert, FCMParams} from './types'; export async function sendFCMToken(params: FCMParams) { const response = await client.post('/fcmToken', params); @@ -11,7 +11,8 @@ export async function sendSingleAlarm(params: SingleAlert) { return response.config.data; } -export async function sendMultiAlarm(params: MultiAlert) { +export async function sendMultiAlarm(params: number) { const response = await client.post('/api/fcm/submit', params); + console.log('Pool User ID Received!'); return response.config.data; } diff --git a/api/fcm/types.ts b/api/fcm/types.ts index 210ad8bb..2b527ffa 100644 --- a/api/fcm/types.ts +++ b/api/fcm/types.ts @@ -1,10 +1,10 @@ export interface SingleAlert { pool_user_id: number; - // brand_id: number; + brand_id: number; } export interface MultiAlert { - pool_user_id: number; + brand_id: number; } export interface FCMParams { diff --git a/screens/CreateMsgScreen.tsx b/screens/CreateMsgScreen.tsx index 676ca166..3024cd4d 100644 --- a/screens/CreateMsgScreen.tsx +++ b/screens/CreateMsgScreen.tsx @@ -71,8 +71,8 @@ function CreateMessageScreen() { refetchOnMount: 'always', }); - const {data: poolId} = useQuery('getUserResult', () => getUser(), { - refetchOnMount: true, + const {data: id} = useQuery('getUserResult', () => getUser(), { + refetchOnMount: 'always', }); const {mutate: create} = useMutation(createMessage, { @@ -81,7 +81,14 @@ function CreateMessageScreen() { }, }); - const {mutate: send} = useMutation(sendMultiAlarm); + const {mutate: send} = useMutation(sendMultiAlarm, { + onSuccess: () => { + console.log('Success!'); + }, + onError: e => { + console.error(e); + }, + }); const onSubmit = useCallback(() => { const formData = new FormData(); @@ -89,8 +96,14 @@ function CreateMessageScreen() { formData.append('messageLink', form.messageLink as string); formData.append('multipartFiles', form.messageImage as Blob); create(formData); - send({pool_user_id: poolId?.poolUserId as number}); - }, [create, form, send]); + // onSuccessSubmit(); + send({brand_id: id?.poolUserId as number}); + }, [create, form]); + + // const onSuccessSubmit = () => { + // send(id?.poolUserId as number); + // console.log(id?.poolUserId as number); + // }; const onChangeText = (prop: string) => (value: string) => { setForm({ From 0efc9c38a4963e79acd3555a1ff83ab2cea1d22d Mon Sep 17 00:00:00 2001 From: Orca1110 Date: Fri, 30 Sep 2022 17:12:44 +0900 Subject: [PATCH 3/4] :goal_net: Lint Error Catching #315 --- api/fcm/index.ts | 5 +++-- screens/CreateMsgScreen.tsx | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/api/fcm/index.ts b/api/fcm/index.ts index 65ef80a7..ce352def 100644 --- a/api/fcm/index.ts +++ b/api/fcm/index.ts @@ -1,5 +1,5 @@ import client from '../client'; -import {SingleAlert, FCMParams} from './types'; +import {SingleAlert, FCMParams, MultiAlert} from './types'; export async function sendFCMToken(params: FCMParams) { const response = await client.post('/fcmToken', params); @@ -8,10 +8,11 @@ export async function sendFCMToken(params: FCMParams) { export async function sendSingleAlarm(params: SingleAlert) { const response = await client.post('/api/fcm/welcome', params); + console.log('Welcome API Worked!'); return response.config.data; } -export async function sendMultiAlarm(params: number) { +export async function sendMultiAlarm(params: MultiAlert) { const response = await client.post('/api/fcm/submit', params); console.log('Pool User ID Received!'); return response.config.data; diff --git a/screens/CreateMsgScreen.tsx b/screens/CreateMsgScreen.tsx index 3024cd4d..7bacfbe0 100644 --- a/screens/CreateMsgScreen.tsx +++ b/screens/CreateMsgScreen.tsx @@ -98,7 +98,7 @@ function CreateMessageScreen() { create(formData); // onSuccessSubmit(); send({brand_id: id?.poolUserId as number}); - }, [create, form]); + }, [create, form, id?.poolUserId]); // const onSuccessSubmit = () => { // send(id?.poolUserId as number); From ab5b63e9322c90ea270b23980da5296b423e29cb Mon Sep 17 00:00:00 2001 From: Orca1110 Date: Fri, 30 Sep 2022 17:15:03 +0900 Subject: [PATCH 4/4] :goal_net: Lint Error #315 --- screens/CreateMsgScreen.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/screens/CreateMsgScreen.tsx b/screens/CreateMsgScreen.tsx index 7bacfbe0..820cd3b2 100644 --- a/screens/CreateMsgScreen.tsx +++ b/screens/CreateMsgScreen.tsx @@ -98,7 +98,7 @@ function CreateMessageScreen() { create(formData); // onSuccessSubmit(); send({brand_id: id?.poolUserId as number}); - }, [create, form, id?.poolUserId]); + }, [create, form, send, id?.poolUserId]); // const onSuccessSubmit = () => { // send(id?.poolUserId as number);