Skip to content

Commit

Permalink
feat(ui): display error message on social callback page (#1097)
Browse files Browse the repository at this point in the history
* feat(ui): display error message on social callback page

display error message on social callback page

* refactor(ui): display server side error message direactly

display server side error message directly
  • Loading branch information
simeng-li authored Jun 10, 2022
1 parent c078cc1 commit f3b8678
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 9 deletions.
1 change: 0 additions & 1 deletion packages/phrases/src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ const translation = {
invalid_passcode: 'The passcode is invalid.',
invalid_connector_auth: 'The authorization is invalid.',
invalid_connector_request: 'The connector data is invalid.',
request: 'Request error: {{message}}',
unknown: 'Unknown error, please try again later.',
invalid_session: 'Session not found. Please go back and sign in again.',
},
Expand Down
1 change: 0 additions & 1 deletion packages/phrases/src/locales/zh-cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ const translation = {
invalid_passcode: '无效的验证码。',
invalid_connector_auth: '登录失败。',
invalid_connector_request: '无效的登录请求。',
request: '请求错误:{{ message }}', // All error messages end with '。'.
unknown: '未知错误,请稍后重试。',
invalid_session: '未找到有效的会话,请重新登录。',
},
Expand Down
7 changes: 7 additions & 0 deletions packages/ui/src/containers/SocialLanding/index.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

.container {
@include _.flex-column;
@include _.full-width;
}

.connector {
Expand All @@ -14,3 +15,9 @@
@include _.image-align-center;
}
}

.message {
text-align: center;
font: var(--font-caption);
color: var(--color-caption);
}
4 changes: 3 additions & 1 deletion packages/ui/src/containers/SocialLanding/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ type Props = {
className?: string;
connectorId: string;
isLoading?: boolean;
message?: string;
};

const SocialLanding = ({ className, connectorId, isLoading = false }: Props) => {
const SocialLanding = ({ className, connectorId, message, isLoading = false }: Props) => {
const { experienceSettings } = useContext(PageContext);
const connector = experienceSettings?.socialConnectors.find(({ id }) => id === connectorId);

Expand All @@ -22,6 +23,7 @@ const SocialLanding = ({ className, connectorId, isLoading = false }: Props) =>
{connector?.logo ? <img src={connector.logo} /> : connectorId}
</div>
{isLoading && <LoadingIcon />}
{!isLoading && message && <div className={styles.message}>{message}</div>}
</div>
);
};
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/hooks/use-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function useApi<Args extends any[], Response>(
return;
}

const { code } = error;
const { code, message } = error;
const handler = errorHandlers?.[code] ?? errorHandlers?.global;

errorHandlers?.callback?.(error);
Expand All @@ -85,7 +85,7 @@ function useApi<Args extends any[], Response>(
return;
}

setToast(t('error.request', { ...error }));
setToast(message);
}, [error, errorHandlers, setToast, t]);

return {
Expand Down
7 changes: 4 additions & 3 deletions packages/ui/src/hooks/use-social-callback-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { PageContext } from './use-page-context';

const useSocialCallbackHandler = () => {
const [loading, setLoading] = useState(true);
const [errorMessage, setErrorMessage] = useState<string>();
const { setToast } = useContext(PageContext);
const { t } = useTranslation(undefined, { keyPrefix: 'main_flow' });
const navigate = useNavigate();
Expand All @@ -17,12 +18,12 @@ const useSocialCallbackHandler = () => {
(connectorId: string) => {
// Apple use fragment mode to store auth parameter. Need to support it.
const data = window.location.search || '?' + window.location.hash.slice(1);
const { state, error, error_description } = parseQueryParameters(data);
const { state, error, error_description = '' } = parseQueryParameters(data);

// Connector auth error
if (error) {
setLoading(false);
setToast(`${error}${error_description ? `: ${error_description}` : ''}`);
setErrorMessage(`${error}${error_description ? `: ${error_description}` : ''}`);

return;
}
Expand Down Expand Up @@ -58,7 +59,7 @@ const useSocialCallbackHandler = () => {
[navigate, setToast, t]
);

return { socialCallbackHandler, loading };
return { socialCallbackHandler, loading, errorMessage };
};

export default useSocialCallbackHandler;
3 changes: 2 additions & 1 deletion packages/ui/src/pages/Callback/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Parameters = {
const Callback = () => {
const { connector: connectorId } = useParams<Parameters>();

const { socialCallbackHandler, loading } = useSocialCallbackHandler();
const { socialCallbackHandler, loading, errorMessage } = useSocialCallbackHandler();

// SocialSignIn Callback Handler
useEffect(() => {
Expand All @@ -33,6 +33,7 @@ const Callback = () => {
className={styles.connectorContainer}
connectorId={connectorId}
isLoading={loading}
message={errorMessage}
/>
</div>
);
Expand Down

0 comments on commit f3b8678

Please sign in to comment.