diff --git a/api/fcm/index.ts b/api/fcm/index.ts index fc80e54..ce352de 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, MultiAlert} from './types'; export async function sendFCMToken(params: FCMParams) { const response = await client.post('/fcmToken', params); @@ -8,10 +8,12 @@ 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: MultiAlert) { 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 3993204..2b527ff 100644 --- a/api/fcm/types.ts +++ b/api/fcm/types.ts @@ -5,7 +5,6 @@ export interface SingleAlert { export interface MultiAlert { brand_id: number; - Message_id: number; } export interface FCMParams { diff --git a/components/profile/FollowButton.tsx b/components/profile/FollowButton.tsx index 3a843bc..ec717e4 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 48ce9ae..820cd3b 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,39 @@ function CreateMessageScreen() { refetchOnMount: 'always', }); + const {data: id} = useQuery('getUserResult', () => getUser(), { + refetchOnMount: 'always', + }); + const {mutate: create} = useMutation(createMessage, { onSuccess: () => { navigation.dispatch(CommonActions.goBack()); }, }); + + const {mutate: send} = useMutation(sendMultiAlarm, { + onSuccess: () => { + console.log('Success!'); + }, + onError: e => { + console.error(e); + }, + }); + 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]); + // onSuccessSubmit(); + send({brand_id: id?.poolUserId as number}); + }, [create, form, send, id?.poolUserId]); + + // const onSuccessSubmit = () => { + // send(id?.poolUserId as number); + // console.log(id?.poolUserId as number); + // }; const onChangeText = (prop: string) => (value: string) => { setForm({