-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(app-crm): use antd list on company and quote card view (#4923)
* refactor(app-crm): use antd list on company and quote card view * chore(app-crm): remove empty space
- Loading branch information
1 parent
ad7dcc8
commit 7f4caa2
Showing
11 changed files
with
332 additions
and
338 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./card"; | ||
export * from "./skeleton"; |
4 changes: 2 additions & 2 deletions
4
.../src/components/company/card-skeleton.tsx → .../src/components/company/card/skeleton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./card"; | ||
export * from "./skeleton"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.