From 7ef4168702519d3ae102068f044e770158e17a52 Mon Sep 17 00:00:00 2001 From: tay suisin Date: Tue, 10 Jan 2023 18:00:15 +0800 Subject: [PATCH 1/2] refactor: ts migration for static url --- .../send-email-template/send-email-template.tsx | 3 ++- .../components/src/components/static-url/index.js | 3 --- .../components/src/components/static-url/index.ts | 3 +++ .../static-url/{static-url.jsx => static-url.tsx} | 14 ++++++++++++-- .../shared/src/utils/platform/platform-context.tsx | 7 ++++++- 5 files changed, 23 insertions(+), 7 deletions(-) delete mode 100644 packages/components/src/components/static-url/index.js create mode 100644 packages/components/src/components/static-url/index.ts rename packages/components/src/components/static-url/{static-url.jsx => static-url.tsx} (56%) diff --git a/packages/components/src/components/send-email-template/send-email-template.tsx b/packages/components/src/components/send-email-template/send-email-template.tsx index c7a299692fb3..82451edc186d 100644 --- a/packages/components/src/components/send-email-template/send-email-template.tsx +++ b/packages/components/src/components/send-email-template/send-email-template.tsx @@ -4,6 +4,7 @@ import { PlatformContext } from '@deriv/shared'; import Icon from '../icon/icon'; import Button from '../button/button'; import Text from '../text'; +import { TPlatformContext } from '../static-url/static-url'; type TSendEmailTemplate = { className?: string; @@ -32,7 +33,7 @@ const SendEmailTemplate = ({ const [is_email_not_received_clicked, setIsEmailNotReceivedClicked] = React.useState(false); const [is_resend_btn_disabled, setIsResendBtnDisabled] = React.useState(false); const [resend_email_btn_text, setResendEmailBtnText] = React.useState(txt_resend); - const { is_appstore } = React.useContext<{ is_pre_appstore: boolean; is_appstore: boolean }>(PlatformContext); + const { is_appstore } = React.useContext(PlatformContext); const timeout_limit = resend_timeout || 60; let resend_interval: number; diff --git a/packages/components/src/components/static-url/index.js b/packages/components/src/components/static-url/index.js deleted file mode 100644 index de3792af5344..000000000000 --- a/packages/components/src/components/static-url/index.js +++ /dev/null @@ -1,3 +0,0 @@ -import StaticUrl from './static-url.jsx'; - -export default StaticUrl; diff --git a/packages/components/src/components/static-url/index.ts b/packages/components/src/components/static-url/index.ts new file mode 100644 index 000000000000..b1ab6e65c7df --- /dev/null +++ b/packages/components/src/components/static-url/index.ts @@ -0,0 +1,3 @@ +import StaticUrl from './static-url'; + +export default StaticUrl; diff --git a/packages/components/src/components/static-url/static-url.jsx b/packages/components/src/components/static-url/static-url.tsx similarity index 56% rename from packages/components/src/components/static-url/static-url.jsx rename to packages/components/src/components/static-url/static-url.tsx index 6dbd744f5b45..0397b51731a0 100644 --- a/packages/components/src/components/static-url/static-url.jsx +++ b/packages/components/src/components/static-url/static-url.tsx @@ -2,8 +2,18 @@ import React from 'react'; import { getStaticUrl, PlatformContext, setUrlLanguage } from '@deriv/shared'; import { getLanguage } from '@deriv/translations'; -const StaticUrl = ({ href, is_document, children, ...props }) => { - const { is_appstore } = React.useContext(PlatformContext); +export type TPlatformContext = { + is_appstore?: boolean; + is_pre_appstore?: boolean; +}; + +type TStaticUrl = { + href?: string; + is_document?: boolean; +}; + +const StaticUrl: React.FC> = ({ href, is_document, children, ...props }) => { + const { is_appstore } = React.useContext(PlatformContext); const getHref = () => { setUrlLanguage(getLanguage()); return getStaticUrl(href, { is_appstore }, is_document); diff --git a/packages/shared/src/utils/platform/platform-context.tsx b/packages/shared/src/utils/platform/platform-context.tsx index c01a64a92eb9..188a0c33f4e1 100644 --- a/packages/shared/src/utils/platform/platform-context.tsx +++ b/packages/shared/src/utils/platform/platform-context.tsx @@ -1,5 +1,10 @@ import React from 'react'; -export const PlatformContext = React.createContext({} as { is_pre_appstore: boolean; is_appstore: boolean }); +export type TPlatformContext = { + is_appstore?: boolean; + is_pre_appstore?: boolean; +}; + +export const PlatformContext = React.createContext({}); PlatformContext.displayName = 'DerivAppStorePlatformContext'; From fd3ed5415c508eb0dab7cb70cbc4754150b3a027 Mon Sep 17 00:00:00 2001 From: tay suisin Date: Wed, 11 Jan 2023 11:33:08 +0800 Subject: [PATCH 2/2] chore: edit type based onn comments given --- packages/components/src/components/static-url/static-url.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/components/src/components/static-url/static-url.tsx b/packages/components/src/components/static-url/static-url.tsx index 0397b51731a0..1d0d5dcef238 100644 --- a/packages/components/src/components/static-url/static-url.tsx +++ b/packages/components/src/components/static-url/static-url.tsx @@ -12,7 +12,7 @@ type TStaticUrl = { is_document?: boolean; }; -const StaticUrl: React.FC> = ({ href, is_document, children, ...props }) => { +const StaticUrl = ({ href, is_document, children, ...props }: React.PropsWithChildren) => { const { is_appstore } = React.useContext(PlatformContext); const getHref = () => { setUrlLanguage(getLanguage());