Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add accordion output #9

Merged
merged 4 commits into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 2 additions & 31 deletions app/admin/AccordionInputForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Button } from '@/components/ui/button';
import { useState } from 'react';
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion';
import { removeEmptyStringFields } from '@/utils';
import JsonView from '@uiw/react-json-view';

type InputFormProps = {
formSchema: z.ZodObject<any, any>;
Expand All @@ -32,36 +33,6 @@ function getDefaultValuesFromSchema(
return values;
}

function DisplayData({ data }: { data: any }) {
if (typeof data === 'string' || typeof data === 'number' || typeof data === 'boolean') {
return <p>{data.toString()}</p>;
}
if (Array.isArray(data)) {
return (
<div>
{data.map((item, index) => (
<DisplayData key={index} data={item} />
))}
</div>
);
}

if (typeof data === 'object' && data !== null) {
return (
<div>
{Object.keys(data).map((key) => (
<div key={key}>
<strong>{key}:</strong>
<DisplayData data={data[key]} />
</div>
))}
</div>
);
}

return null; // fallback for unsupported data types
}

type NestedFieldProps = {
control: any;
name: string;
Expand Down Expand Up @@ -165,7 +136,7 @@ export default function AccordionInputForm({
/>
))}
<Button type="submit">Submit</Button>
<DisplayData data={result.data} />
<JsonView value={result} />
</form>
</Form>
</AccordionContent>
Expand Down
3 changes: 1 addition & 2 deletions app/ipa/[ipOrgId]/[ipAssetId]/AssetDisplayComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { getRoundedTime } from '@/utils';

export default function AssetDisplayComponent({ data }: { data: IPAsset }) {
const [imageUrl, setImageUrl] = useState<string | null>(null);

if (data.mediaUrl) {
fetch(data.mediaUrl)
.then((response) => {
Expand All @@ -18,7 +17,7 @@ export default function AssetDisplayComponent({ data }: { data: IPAsset }) {
})
.then((data) => {
// Step 2: Access property values from the JavaScript object
const imageURI = data.imageURI; // Replace 'propertyName' with the actual property name in your JSON data
const imageURI = data.image; // Replace 'propertyName' with the actual property name in your JSON data
console.log('imageURI', imageURI);
setImageUrl(imageURI);
})
Expand Down
2 changes: 1 addition & 1 deletion components/cards/AssetCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function AssetCard({ data }: { data: IPAsset }) {
})
.then((data) => {
// Step 2: Access property values from the JavaScript object
const imageURI = data.imageURI; // Replace 'propertyName' with the actual property name in your JSON data
const imageURI = data.image; // Replace 'propertyName' with the actual property name in your JSON data
console.log('imageURI', imageURI);
setImageUrl(imageURI);
})
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@radix-ui/react-toast": "^1.1.5",
"@radix-ui/react-tooltip": "^1.0.7",
"@rainbow-me/rainbowkit": "^1.3.0",
"@story-protocol/core-sdk": "0.1.0-alpha-rc.7",
"@story-protocol/core-sdk": "0.1.0-alpha",
"@tanstack/react-table": "^8.10.7",
"@uiw/react-json-view": "2.0.0-alpha.10",
"@web3modal/wagmi": "^3.1.0",
Expand Down
Loading
Loading