Skip to content

Commit

Permalink
refactor(app-crm): use antd list on company and quote card view (#4923)
Browse files Browse the repository at this point in the history
* refactor(app-crm): use antd list on company and quote card view

* chore(app-crm): remove empty space
  • Loading branch information
alicanerdurmaz authored Sep 11, 2023
1 parent ad7dcc8 commit 7f4caa2
Show file tree
Hide file tree
Showing 11 changed files with 332 additions and 338 deletions.
328 changes: 66 additions & 262 deletions examples/app-crm/src/components/company/card-view.tsx

Large diffs are not rendered by default.

179 changes: 179 additions & 0 deletions examples/app-crm/src/components/company/card/card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
import { FC } from "react";
import { useDelete, useNavigation } from "@refinedev/core";
import { Button, Card, Dropdown, Space, Tooltip } from "antd";
import { DeleteOutlined, EyeOutlined, MoreOutlined } from "@ant-design/icons";
import { Text, CustomAvatar } from "../..";
import { currencyNumber } from "../../../utilities";
import { Company } from "../../../interfaces/graphql";
import { CustomAvatarGroup } from "../../custom-avatar-group";
import { CompanyCardSkeleton } from "./skeleton";

type Props = {
company: Company | null;
};

export const CompanyCard: FC<Props> = ({ company }) => {
const { edit } = useNavigation();
const { mutate } = useDelete();

if (!company) return <CompanyCardSkeleton />;

const relatedContactAvatars = company?.contacts?.nodes?.map((contact) => {
return {
name: contact.name,
src: contact.avatarUrl as string | undefined,
};
});

return (
<Card
size="small"
actions={[
<div
key="1"
style={{
width: "100%",
height: "60px",
display: "flex",
justifyContent: "space-between",
alignItems: "flex-start",
padding: "0 16px",
}}
>
<div
style={{
display: "flex",
flexDirection: "column",
alignItems: "flex-start",
gap: "6px",
}}
>
<Text size="xs">Related contacts</Text>
<CustomAvatarGroup
size={"small"}
overlap
gap="4px"
avatars={relatedContactAvatars}
/>
</div>
<div
style={{
display: "flex",
flexDirection: "column",
alignItems: "flex-end",
gap: "6px",
}}
>
<Text size="xs">Sales owner</Text>
<Tooltip
title={company.salesOwner?.name}
key={company.salesOwner?.id}
>
<CustomAvatar
name={company.salesOwner?.name}
src={company.salesOwner?.avatarUrl}
/>
</Tooltip>
</div>
</div>,
]}
>
<div
style={{
display: "flex",
flexDirection: "column",
alignItems: "center",
position: "relative",
}}
>
<Dropdown
menu={{
items: [
{
label: "View company",
key: "1",
icon: <EyeOutlined />,
onClick: () => {
edit("companies", company.id);
},
},
{
danger: true,
label: "Delete company",
key: "2",
icon: <DeleteOutlined />,
onClick: () => {
mutate({
resource: "company",
id: company.id,
});
},
},
],
}}
placement="bottom"
arrow
>
<Button
type="text"
shape="circle"
style={{
position: "absolute",
top: 0,
right: 0,
}}
icon={
<MoreOutlined
style={{
transform: "rotate(90deg)",
}}
/>
}
/>
</Dropdown>

<CustomAvatar
name={company.name}
src={company.avatarUrl}
shape="square"
style={{
width: "48px",
height: "48px",
}}
/>
<Text
strong
size="md"
ellipsis={{ tooltip: company.name }}
style={{
marginTop: "12px",
}}
>
{company.name}
</Text>

<Space
direction="vertical"
size={0}
style={{
marginTop: "8px",
alignItems: "center",
}}
>
<Text type="secondary">Open deals amount</Text>
<Text
strong
size="md"
style={{
marginTop: "12px",
}}
>
{currencyNumber(
company?.dealsAggregate?.[0].sum?.value || 0,
)}
</Text>
</Space>
</div>
</Card>
);
};
2 changes: 2 additions & 0 deletions examples/app-crm/src/components/company/card/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./card";
export * from "./skeleton";
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Card, Skeleton, Space } from "antd";
import { Text } from "..";
import { Text } from "../..";

export const CardSkeleton = () => {
export const CompanyCardSkeleton = () => {
return (
<Card
size="small"
Expand Down
110 changes: 61 additions & 49 deletions examples/app-crm/src/components/contact/card-view.tsx
Original file line number Diff line number Diff line change
@@ -1,68 +1,80 @@
import { Col, Pagination, Row, type TableProps } from "antd";

import { ContactCard } from "./card";
import { List, type TableProps } from "antd";
import { ContactCard } from "./card/card";
import { Contact } from "../../interfaces/graphql";
import { CardSkeleton } from "./card/skeleton";
import { PaginationTotal } from "../pagination-total";
import { ListProps } from "antd/lib";
import { useMemo } from "react";
import { ContactCardSkeleton } from "./card/skeleton";

type Props = {
tableProps: TableProps<Contact>;
setCurrent: (current: number) => void;
setPageSize: (pageSize: number) => void;
loading?: boolean;
};

export const CardView: React.FC<Props> = ({
tableProps: { dataSource, pagination },
tableProps: { dataSource, pagination, loading },
setCurrent,
setPageSize,
loading,
}) => {
const data = useMemo(() => {
return [...(dataSource || [])];
}, [dataSource]);

return (
<div
style={{
marginTop: "1rem",
<List
grid={{
gutter: 32,
column: 4,
xs: 1,
sm: 1,
md: 2,
lg: 2,
xl: 4,
}}
>
<Row gutter={[32, 32]}>
{loading
? Array.from({ length: 12 }).map((_, index) => {
return (
<Col
key={index}
span="6"
lg={{ span: 6 }}
md={{ span: 12 }}
xs={{ span: 24 }}
>
<CardSkeleton />
</Col>
);
})
: dataSource?.map((contact) => (
<Col
key={contact.id}
span="6"
lg={{ span: 6 }}
md={{ span: 12 }}
xs={{ span: 24 }}
>
<ContactCard contact={contact} />
</Col>
))}
</Row>

<Pagination
style={{ display: "flex", marginTop: "1rem" }}
{...pagination}
showTotal={(total) => (
<PaginationTotal total={total} entityName="contacts" />
)}
onChange={(page, pageSize) => {
dataSource={data}
renderItem={(item) => (
<List.Item>
<ContactCard contact={item} />
</List.Item>
)}
pagination={{
...(pagination as ListProps<Contact>["pagination"]),
hideOnSinglePage: true,
itemRender: undefined,
position: "bottom",
style: { display: "flex", marginTop: "1rem" },
pageSizeOptions: ["12", "24", "48"],
onChange: (page, pageSize) => {
setCurrent(page);
setPageSize(pageSize);
}}
/>
</div>
},
showTotal: (total) => (
<PaginationTotal total={total} entityName="contacts" />
),
}}
>
{loading ? (
<List
grid={{
gutter: 32,
column: 4,
xs: 1,
sm: 1,
md: 2,
lg: 2,
xl: 4,
}}
dataSource={Array.from({ length: 12 }).map((_, i) => ({
id: i,
}))}
renderItem={() => (
<List.Item>
<ContactCardSkeleton />
</List.Item>
)}
/>
) : undefined}
</List>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@ import { CustomAvatar } from "../../custom-avatar";
import { Contact } from "../../../interfaces/graphql";

import styles from "./index.module.css";
import { ContactCardSkeleton } from "./skeleton";

type ContactCardProps = {
contact: Contact;
contact: Contact | null;
};

export const ContactCard: React.FC<ContactCardProps> = ({ contact }) => {
const { name, email, status, jobTitle, company, avatarUrl, id } = contact;

const navigate = useNavigate();
const getToPath = useGetToPath();
const { mutate: deleteMutate } = useDelete();

if (!contact) return <ContactCardSkeleton />;

const { name, email, status, jobTitle, company, avatarUrl, id } = contact;
const items: MenuProps["items"] = [
{
label: "Show",
Expand Down
14 changes: 7 additions & 7 deletions examples/app-crm/src/components/contact/card/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@

.dropdown {
position: absolute;
top: .75rem;
right: .75rem;
top: 0.75rem;
right: 0.75rem;
}

.personal {
padding: .75rem;
padding: 0.75rem;
width: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-content: center;
align-items: center;
text-align: center;
gap: .5rem;
gap: 0.5rem;
}

.company {
display: flex;
flex-direction: column;
padding: .75rem 1rem;
gap: .5rem;
padding: 0.75rem 1rem;
gap: 0.5rem;
border-top: 1px solid rgba(240, 240, 240, 1);
text-align: center;
}
}
}
2 changes: 2 additions & 0 deletions examples/app-crm/src/components/contact/card/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./card";
export * from "./skeleton";
2 changes: 1 addition & 1 deletion examples/app-crm/src/components/contact/card/skeleton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Card, Skeleton, Space } from "antd";

export const CardSkeleton = () => {
export const ContactCardSkeleton = () => {
return (
<Card
size="small"
Expand Down
Loading

0 comments on commit 7f4caa2

Please sign in to comment.