Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,64 +1,11 @@
'use client';

import { useParams, useRouter } from 'next/navigation';
import { graphql } from '@/gql';
import { useMutation } from '@tanstack/react-query';
import { Button, Icon, Text, toast } from 'opub-ui';
import { Button, Icon, Text } from 'opub-ui';
import { twMerge } from 'tailwind-merge';

import { GraphQL } from '@/lib/api';
import { Icons } from '@/components/icons';

const createDatasetMutationDoc: any = graphql(`
mutation Generate_Dataset_Name {
addDataset {
success
errors {
fieldErrors {
messages
}
}
data {
id
title
created
}
}
}
`);
export const Content = () => {
const router = useRouter();
const params = useParams<{ entityType?: string; entitySlug?: string }>();
const entityType = params?.entityType;
const entitySlug = params?.entitySlug;

const isValidParams =
typeof entityType === 'string' && typeof entitySlug === 'string';

const ownerArgs: Record<string, string> | null = isValidParams
? { [entityType]: entitySlug }
: null;

const CreateDatasetMutation: { mutate: any; isLoading: boolean; error: any } =
useMutation(() => GraphQL(createDatasetMutationDoc, ownerArgs || {}, []), {
onSuccess: (data: any) => {
if (data.addDataset.success) {
toast('Dataset created successfully!');
if (isValidParams && entityType && entitySlug) {
router.push(
`/dashboard/${entityType}/${entitySlug}/dataset/${data?.addDataset?.data?.id}/edit/metadata`
);
}
} else {
toast('Error: ' + data.addDataset.errors.fieldErrors[0].messages[0]);
}
},
});

if (!isValidParams) {
return null;
}

export const Content = ({ onAddNew }: { onAddNew: () => void }) => {
return (
<div className="flex h-full w-full grow flex-col items-center justify-center">
<div className={twMerge('h-100 flex flex-col items-center gap-4')}>
Expand All @@ -71,9 +18,7 @@ export const Content = () => {
<Text variant="headingSm" color="subdued">
You have not added any datasets yet.
</Text>
<Button onClick={() => CreateDatasetMutation.mutate()}>
Add New Dataset
</Button>
<Button onClick={onAddNew}>Add New Dataset</Button>
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const Page = () => {
isLoading={isLoading}
/>

<Content />
<Content onAddNew={() => mutate()} />
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ export default function DatasetPage() {
) : AllDatasetsQuery.isLoading ? (
<Loading />
) : (
<Content />
<Content onAddNew={() => setIsTypeModalOpen(true)} />
)}

{/* <Page /> */}
Expand Down
Loading