-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(examples): add show component and test to data-provider-strapi-v4
- Loading branch information
1 parent
e8950bc
commit 32af68a
Showing
7 changed files
with
183 additions
and
2 deletions.
There are no files selected for viewing
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
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
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,85 @@ | ||
import { useShow, IResourceComponentsProps, useOne } from "@refinedev/core"; | ||
|
||
import { | ||
Show, | ||
MarkdownField, | ||
ListButton, | ||
EditButton, | ||
RefreshButton, | ||
ImageField, | ||
} from "@refinedev/antd"; | ||
|
||
import { Space, Typography } from "antd"; | ||
|
||
import { IPost, ICategory } from "interfaces"; | ||
import { API_URL } from "../../constants"; | ||
|
||
const { Title, Text } = Typography; | ||
|
||
export const PostShow: React.FC<IResourceComponentsProps> = () => { | ||
const { queryResult } = useShow<IPost>({ | ||
metaData: { populate: ["category", "cover"] }, | ||
}); | ||
|
||
const { data, isLoading } = queryResult; | ||
const record = data?.data; | ||
|
||
const { data: categoryData, isLoading: categoryIsLoading } = | ||
useOne<ICategory>({ | ||
resource: "categories", | ||
id: record?.category?.id || "", | ||
queryOptions: { | ||
enabled: !!record, | ||
}, | ||
}); | ||
|
||
const handleRefresh = () => { | ||
queryResult.refetch(); | ||
}; | ||
|
||
return ( | ||
<Show | ||
isLoading={isLoading} | ||
headerProps={{ | ||
extra: ( | ||
<> | ||
<ListButton /> | ||
<EditButton /> | ||
<RefreshButton onClick={handleRefresh} /> | ||
</> | ||
), | ||
}} | ||
> | ||
<Title level={5}>Id</Title> | ||
<Text>{record?.id}</Text> | ||
|
||
<Title level={5}>Title</Title> | ||
<Text>{record?.title}</Text> | ||
|
||
<Title level={5}>Category</Title> | ||
<Text> | ||
{categoryIsLoading ? "Loading..." : categoryData?.data?.title} | ||
</Text> | ||
|
||
<Title level={5}>Content</Title> | ||
<MarkdownField value={record?.content} /> | ||
|
||
<Title level={5}>Images</Title> | ||
<Space wrap> | ||
{record?.cover ? ( | ||
record?.cover.map((attributes) => { | ||
return ( | ||
<ImageField | ||
key={attributes.id} | ||
value={`${API_URL}${attributes.url}`} | ||
width={200} | ||
/> | ||
); | ||
}) | ||
) : ( | ||
<Text>Not found any images</Text> | ||
)} | ||
</Space> | ||
</Show> | ||
); | ||
}; |