Skip to content

Commit

Permalink
Merge pull request #323 from develo-pool/fix/#315-FCM_API
Browse files Browse the repository at this point in the history
Fix/#315 fcm api
  • Loading branch information
Orca1110 authored Sep 30, 2022
2 parents c48efb7 + ab5b63e commit 6b950de
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
4 changes: 3 additions & 1 deletion api/fcm/index.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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;
}
1 change: 0 additions & 1 deletion api/fcm/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export interface SingleAlert {

export interface MultiAlert {
brand_id: number;
Message_id: number;
}

export interface FCMParams {
Expand Down
5 changes: 3 additions & 2 deletions components/profile/FollowButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -30,6 +29,7 @@ function FollowButton({isFollowed, poolUserId, refetch}: Props) {
refetch();
},
});
// const {mutate: sendWelcome} = useMutation(sendSingleAlarm);

return (
<View style={styles.FollowButton}>
Expand All @@ -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})
}>
<Text style={[styles.FollowText, isFollowed && styles.UnfollowedText]}>
{isFollowed ? '팔로잉' : '팔로우'}
Expand Down
25 changes: 24 additions & 1 deletion screens/CreateMsgScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit 6b950de

Please sign in to comment.