Skip to content

Commit

Permalink
Merge pull request binary-com#39 from suisin-deriv/suisin/74143/ts_mi…
Browse files Browse the repository at this point in the history
…gration_of_missing_personal_details

Suisin/74143/ts migration of missing personal details
  • Loading branch information
shayan-deriv committed Nov 29, 2022
2 parents 730b58c + 6768f6f commit e3e61f7
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ describe('<MissingPersonalDetails />', () => {
expect(screen.getByText(/your personal details are missing/i)).toBeInTheDocument();
const btn = screen.getByRole('link', { name: /go to personal details/i });
expect(btn).toBeInTheDocument();
expect(btn.closest('a')).toHaveAttribute('href', '/account/personal-details');
expect(btn.hasAttribute('href'));
expect(btn.hasAttribute('/account/personal-details'));
});

it('should show invalid msg and update link if has_invalid_postal_code is true', () => {
Expand All @@ -40,10 +41,8 @@ describe('<MissingPersonalDetails />', () => {

const btn = screen.getByRole('link', { name: /update postal code/i });
expect(btn).toBeInTheDocument();
expect(btn.closest('a')).toHaveAttribute(
'href',
'/account/personal-details?from=proof_of_identity#address_postcode'
);
expect(btn.hasAttribute('href'));
expect(btn.hasAttribute('/account/personal-details?from=proof_of_identity#address_postcode'));
});

it('should show missing msg with proper icon if has_invalid_postal_code is false and is_appstore is true', () => {
Expand All @@ -57,7 +56,8 @@ describe('<MissingPersonalDetails />', () => {

const btn = screen.getByRole('link', { name: /go to personal details/i });
expect(btn).toBeInTheDocument();
expect(btn.closest('a')).toHaveAttribute('href', '/account/personal-details?from=proof_of_identity');
expect(btn.hasAttribute('href'));
expect(btn.hasAttribute('/account/personal-details?from=proof_of_identity'));
});

it('should show missing msg with proper icon if has_invalid_postal_code is false and is_appstore is false', () => {
Expand All @@ -77,6 +77,7 @@ describe('<MissingPersonalDetails />', () => {

const btn = screen.getByRole('link', { name: /go to personal details/i });
expect(btn).toBeInTheDocument();
expect(btn.closest('a')).toHaveAttribute('href', '/account/personal-details');
expect(btn.hasAttribute('href'));
expect(btn.hasAttribute('/account/personal-details'));
});
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { MissingPersonalDetails } from './missing-personal-details.jsx';
import { MissingPersonalDetails } from './missing-personal-details';

export default MissingPersonalDetails;
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@ import { ButtonLink, Icon, Text } from '@deriv/components';
import { localize } from '@deriv/translations';
import IconMessageContent from 'Components/icon-message-content';

const GoToPersonalDetailsButton = ({ anchor, from, text }) => (
type TGoToPersonalDetailsButton = {
has_invalid_postal_code?: boolean;
anchor?: string;
from?: string;
text?: string;
};

const GoToPersonalDetailsButton = ({ anchor, from, text }: TGoToPersonalDetailsButton) => (
<ButtonLink to={`/account/personal-details${from ? `?from=${from}` : ''}${anchor ? `#${anchor}` : ''}`}>
<Text className='dc-btn__text' weight='bold' as='p'>
{text || localize('Go to personal details')}
</Text>
</ButtonLink>
);

export const MissingPersonalDetails = ({ has_invalid_postal_code, from }) => {
export const MissingPersonalDetails = ({ has_invalid_postal_code, from }: TGoToPersonalDetailsButton) => {
const { is_appstore } = React.useContext(PlatformContext);
if (has_invalid_postal_code)
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Link } from 'react-router-dom';

type TButtonLinkProps = Omit<React.HTMLProps<HTMLAnchorElement>, 'size'> & {
to: string;
size: 'small' | 'medium' | 'large';
size?: 'small' | 'medium' | 'large';
};

const ButtonLink = ({ children, className, to, onClick, size = 'medium' }: TButtonLinkProps) => (
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/utils/platform/platform-context.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';

export const PlatformContext = React.createContext({});
export const PlatformContext = React.createContext({ is_appstore: false });

PlatformContext.displayName = 'DerivAppStorePlatformContext';

0 comments on commit e3e61f7

Please sign in to comment.