Skip to content

Commit 5596452

Browse files
committed
Fix image add mutation and also add redirect to the mutation
1 parent 9b6ab19 commit 5596452

File tree

1 file changed

+9
-5
lines changed
  • app/[locale]/dashboard/[entityType]/[entitySlug]/charts/components

1 file changed

+9
-5
lines changed

app/[locale]/dashboard/[entityType]/[entitySlug]/charts/components/ChartEditor.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useEffect, useState } from 'react';
2-
import { useParams } from 'next/navigation';
2+
import { useParams, useRouter } from 'next/navigation';
33
import { graphql } from '@/gql';
44
import { ResourceChartImageInput } from '@/gql/generated/graphql';
55
import { useMutation, useQuery } from '@tanstack/react-query';
@@ -111,6 +111,8 @@ const ChartImageUpload = ({
111111

112112
const [selectedDataset, setSelectedDataset] = useState<any>(null);
113113

114+
const router = useRouter();
115+
114116
const createResourceChartImageMutation: {
115117
mutate: any;
116118
isLoading: boolean;
@@ -126,8 +128,12 @@ const ChartImageUpload = ({
126128
{ input: input }
127129
),
128130
{
129-
onSuccess: () => {
131+
onSuccess: (resp: any) => {
130132
toast(`Created chart image successfully`);
133+
// Navigate to chart image preview page
134+
router.push(
135+
`/dashboard/${params.entityType}/${params.entitySlug}/charts/${resp?.createResourceChartImage?.id}?type=TypeResourceChartImage`
136+
);
131137
},
132138
onError: (err: any) => {
133139
toast('Error: ' + err.message.split(':')[0]);
@@ -136,10 +142,9 @@ const ChartImageUpload = ({
136142
);
137143

138144
const handleAddImage = () => {
139-
console.log('Add Image :::', selectedDataset, files);
140145
if (selectedDataset && files) {
141146
createResourceChartImageMutation.mutate({
142-
dataset: { set: selectedDataset },
147+
dataset: selectedDataset,
143148
image: files,
144149
});
145150
}
@@ -178,7 +183,6 @@ const ChartImageUpload = ({
178183
label="Select Chart Image"
179184
accept=".png,.jpg,.jpeg,.svg,.tiff"
180185
onDrop={(val) => {
181-
console.log('drop ::', val);
182186
setFiles(val[0]);
183187
}}
184188
outline

0 commit comments

Comments
 (0)