Skip to content
This repository has been archived by the owner on May 7, 2023. It is now read-only.

Commit

Permalink
Fix rerender issue after signIn
Browse files Browse the repository at this point in the history
  • Loading branch information
hyochan committed May 18, 2022
1 parent 57b2ada commit 4fec2bc
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions client/src/components/pages/SignIn/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
SvgFacebook,
SvgGoogle,
} from '../../../utils/Icons';
import React, {FC, ReactElement, useEffect, useState} from 'react';
import React, {FC, ReactElement, useCallback, useEffect, useState} from 'react';
import type {
UserSignInAppleMutation,
UserSignInAppleMutation$data,
Expand Down Expand Up @@ -144,21 +144,27 @@ const SignIn: FC = () => {
const [commitNotification] =
useMutation<NotificationCreateNotificationMutation>(createNotification);

const createNotificationIfPushTokenExists = async (): Promise<void> => {
const pushToken = await AsyncStorage.getItem('push_token');
const createNotificationIfPushTokenExists =
useCallback(async (): Promise<void> => {
const pushToken = await AsyncStorage.getItem('push_token');

if (pushToken) {
const createNotificationMutationConfig = {
variables: {
token: pushToken,
device: Device.modelName,
os: Device.osName,
},
};
if (pushToken) {
const createNotificationMutationConfig = {
variables: {
token: pushToken,
device: Device.modelName,
os: Device.osName,
},
};

commitNotification(createNotificationMutationConfig);
}
};
commitNotification(createNotificationMutationConfig);
}
}, [commitNotification]);

const handleUserCreated = useCallback(() => {
createNotificationIfPushTokenExists();
loadMeQuery({}, {fetchPolicy: 'network-only'});
}, [createNotificationIfPushTokenExists, loadMeQuery]);

const signIn = async (): Promise<void> => {
if (!validateEmail(email)) {
Expand Down Expand Up @@ -530,20 +536,14 @@ const SignIn: FC = () => {
svgIcon={
<SvgFacebook width={18} height={18} fill={colors.facebook} />
}
onUserCreated={() => {
createNotificationIfPushTokenExists();
loadMeQuery({}, {fetchPolicy: 'network-only'});
}}
onUserCreated={handleUserCreated}
socialProvider={'facebook'}
/>
<SocialSignInButton
svgIcon={
<SvgGoogle width={20} height={20} fill={colors.google} />
}
onUserCreated={() => {
createNotificationIfPushTokenExists();
loadMeQuery({}, {fetchPolicy: 'network-only'});
}}
onUserCreated={handleUserCreated}
socialProvider="google"
/>
</SocialButtonWrapper>
Expand Down

0 comments on commit 4fec2bc

Please sign in to comment.