Skip to content

Commit

Permalink
feat: add callto link to user details (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
kilya11 authored May 22, 2024
1 parent d71182d commit fc007dc
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 4 deletions.
19 changes: 19 additions & 0 deletions src/UserDetailsPopover/PhoneRow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { PhoneOutlined } from '@ant-design/icons';
import React from 'react';

import { Anchor } from '../Anchor';

import { RowWithLabel } from './RowWithLabel';
import { callToLink } from './phone';

type PhoneRowProps = {
phone: string;
};

export function PhoneRow({ phone }: PhoneRowProps) {
return (
<RowWithLabel label={<PhoneOutlined />}>
<Anchor href={callToLink(phone)}>{phone}</Anchor>
</RowWithLabel>
);
}
16 changes: 12 additions & 4 deletions src/UserDetailsPopover/UserDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Space } from '../Space';
import { Typography } from '../Typography';

import { EmailRow } from './EmailRow';
import { PhoneRow } from './PhoneRow';
import { GUTTER, SPACE } from './constants';

type User = {
Expand All @@ -16,6 +17,7 @@ type User = {
firstname?: string | null;
inactive?: boolean;
lastname?: string | null;
phone?: string | null;
username: string;
};

Expand All @@ -24,7 +26,8 @@ export type UserDetailsProps = {
};

export function UserDetails({ user }: UserDetailsProps) {
const { acronym, email, firstname, lastname, inactive, username } = user;
const { acronym, email, firstname, lastname, inactive, username, phone } =
user;
const fullName = joinNonEmpty([firstname, lastname], ' ');
const showFullName = !inactive && fullName;
return (
Expand Down Expand Up @@ -54,9 +57,14 @@ export function UserDetails({ user }: UserDetailsProps) {

<Divider style={{ marginTop: SPACE, marginBottom: SPACE }} />

{inactive
? 'The user was deactivated'
: email && <EmailRow email={email} />}
{inactive ? (
'The user was deactivated'
) : (
<>
{email && <EmailRow email={email} />}
{phone && <PhoneRow phone={phone} />}
</>
)}
</Space>
);
}
3 changes: 3 additions & 0 deletions src/UserDetailsPopover/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default {
email: { control: { type: 'text' }, defaultValue: '[email protected]' },
firstname: { control: { type: 'text' }, defaultValue: 'John' },
lastname: { control: { type: 'text' }, defaultValue: 'Doe' },
phone: { control: { type: 'text' }, defaultValue: '123' },
username: { control: { type: 'text' }, defaultValue: 'jdoe' },
inactive: {
control: {
Expand Down Expand Up @@ -56,6 +57,7 @@ export const Default: Story = function Link(args) {
firstname: args.firstname,
lastname: args.lastname,
username: args.username,
phone: args.phone,
inactive: args.inactive,
}
}
Expand All @@ -73,6 +75,7 @@ export const WithCustomChildren: Story = function Link(args) {
firstname: args.firstname,
lastname: args.lastname,
username: args.username,
phone: args.phone,
inactive: args.inactive,
}),
[args],
Expand Down
12 changes: 12 additions & 0 deletions src/UserDetailsPopover/phone.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { callToLink } from './phone';

describe('callToLink', () => {
it('throws error when phone is empty ', () => {
expect(() => callToLink('')).toThrow(/empty/);
});

it('renders callto link ', () => {
const phone = '123';
expect(callToLink(phone)).toBe(`callto:${phone}`);
});
});
7 changes: 7 additions & 0 deletions src/UserDetailsPopover/phone.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function callToLink(phone: string): string {
if (!phone) {
throw new Error('Could not create callto-Link because phone is empty');
}

return `callto:${phone}`;
}

0 comments on commit fc007dc

Please sign in to comment.