Skip to content

Commit 6a009a1

Browse files
authored
Merge pull request #380 from CivicDataLab/33-while-creation-of-the-models-sometimes-the-toast-appears-to-be-blank-especially-after-the-publish-of-ai-model
Fixed Stacking up of toast
2 parents d7dd14e + 1c3fa17 commit 6a009a1

12 files changed

Lines changed: 79 additions & 53 deletions

File tree

app/[locale]/dashboard/[entityType]/[entitySlug]/aimodels/edit/[id]/details/page.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ export default function AIModelDetailsPage() {
126126
const [isTagsListUpdated, setIsTagsListUpdated] = useState(false);
127127
const SAVE_SUCCESS_TOAST_ID = 'ai-model-details-save-success';
128128
const SAVE_ERROR_TOAST_ID = 'ai-model-details-save-error';
129+
const AI_MODEL_VALIDATION_TOAST_ID = 'ai-model-details-validation-toast';
129130
const isValidHttpUrl = (value: string) => {
130131
try {
131132
const parsed = new URL(value);
@@ -304,7 +305,9 @@ export default function AIModelDetailsPage() {
304305
}
305306

306307
if (!isValidHttpUrl(trimmedWebsite)) {
307-
toast('Please enter a valid URL that includes https.');
308+
toast('Please enter a valid URL that includes https.', {
309+
id: AI_MODEL_VALIDATION_TOAST_ID,
310+
});
308311
return;
309312
}
310313

@@ -321,7 +324,7 @@ export default function AIModelDetailsPage() {
321324

322325
// Ensure access type is always 'open' (required field)
323326
if (dataToUse.accessType !== 'open') {
324-
toast('Open access is required for all models');
327+
toast('Open access is required for all models',{id: OPEN_ACCESS_REQUIRED_TOAST_ID});
325328
setStatus('unsaved');
326329
return;
327330
}
@@ -431,7 +434,7 @@ export default function AIModelDetailsPage() {
431434
</div>
432435
);
433436
}
434-
437+
const OPEN_ACCESS_REQUIRED_TOAST_ID = SAVE_SUCCESS_TOAST_ID;
435438
return (
436439
<div className="flex flex-col gap-4 py-6">
437440
{/* Model Type & Domain - side by side */}

app/[locale]/dashboard/[entityType]/[entitySlug]/aimodels/edit/[id]/versions/page.tsx

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ export default function VersionsPage() {
197197
framework: '',
198198
});
199199

200+
const VERSIONS_ACTION_TOAST_ID = 'aimodel-versions-action-toast';
201+
const VERSIONS_VALIDATION_TOAST_ID = 'aimodel-versions-validation-toast';
200202
// Fetch model versions - override default refetchOnMount: false
201203
const { data, isLoading, refetch } = useQuery(
202204
[`fetch_model_versions_${params.id}`],
@@ -225,7 +227,7 @@ export default function VersionsPage() {
225227
),
226228
{
227229
onSuccess: async (response: any) => {
228-
toast('New version created successfully!');
230+
toast('New version created successfully!',{id: VERSIONS_ACTION_TOAST_ID});
229231
setIsNewVersionModalOpen(false);
230232
resetVersionForm();
231233
queryClient.invalidateQueries([`fetch_AIModelForPublish_${params.id}`]);
@@ -246,7 +248,7 @@ export default function VersionsPage() {
246248
}
247249
},
248250
onError: (error: any) => {
249-
toast(`Error: ${error.message}`);
251+
toast(`Error: ${error.message}`,{id: VERSIONS_ACTION_TOAST_ID});
250252
},
251253
}
252254
);
@@ -261,7 +263,7 @@ export default function VersionsPage() {
261263
),
262264
{
263265
onSuccess: async () => {
264-
toast('Provider added successfully!');
266+
toast('Provider added successfully!',{id: VERSIONS_ACTION_TOAST_ID});
265267
setIsProviderModalOpen(false);
266268
resetProviderForm();
267269
queryClient.invalidateQueries([
@@ -282,7 +284,7 @@ export default function VersionsPage() {
282284
}
283285
},
284286
onError: (error: any) => {
285-
toast(`Error: ${error.message}`);
287+
toast(`Error: ${error.message}`,{id: VERSIONS_ACTION_TOAST_ID});
286288
},
287289
}
288290
);
@@ -296,7 +298,7 @@ export default function VersionsPage() {
296298
),
297299
{
298300
onSuccess: async () => {
299-
toast('Provider updated successfully!');
301+
toast('Provider updated successfully!',{id: VERSIONS_ACTION_TOAST_ID});
300302
setIsProviderModalOpen(false);
301303
setEditingProvider(null);
302304
resetProviderForm();
@@ -318,7 +320,7 @@ export default function VersionsPage() {
318320
}
319321
},
320322
onError: (error: any) => {
321-
toast(`Error: ${error.message}`);
323+
toast(`Error: ${error.message}`,{id: VERSIONS_ACTION_TOAST_ID});
322324
},
323325
}
324326
);
@@ -332,7 +334,7 @@ export default function VersionsPage() {
332334
),
333335
{
334336
onSuccess: async () => {
335-
toast('Provider deleted successfully!');
337+
toast('Provider deleted successfully!',{id: VERSIONS_ACTION_TOAST_ID});
336338
queryClient.invalidateQueries([`fetch_AIModelForPublish_${params.id}`]);
337339

338340
// Force refetch and update selected version after provider deletion
@@ -349,7 +351,7 @@ export default function VersionsPage() {
349351
}
350352
},
351353
onError: (error: any) => {
352-
toast(`Error: ${error.message}`);
354+
toast(`Error: ${error.message}`,{id: VERSIONS_ACTION_TOAST_ID});
353355
},
354356
}
355357
);
@@ -415,11 +417,11 @@ export default function VersionsPage() {
415417

416418
const handleSaveNewVersion = () => {
417419
if (!newVersionData.version) {
418-
toast('Please enter a version number');
420+
toast('Please enter a version number', { id: VERSIONS_VALIDATION_TOAST_ID });
419421
return;
420422
}
421423
if (!newVersionData.lifecycleStage) {
422-
toast('Please select a lifecycle stage');
424+
toast('Please select a lifecycle stage', { id: VERSIONS_VALIDATION_TOAST_ID });
423425
return;
424426
}
425427

@@ -486,20 +488,25 @@ export default function VersionsPage() {
486488
);
487489

488490
if (isEndpointRequired && !providerFormData.apiEndpointUrl?.trim()) {
489-
toast('Endpoint URL is required for the selected provider.');
491+
toast('Endpoint URL is required for the selected provider.', {
492+
id: VERSIONS_VALIDATION_TOAST_ID,
493+
});
490494
return;
491495
}
492496

493497
if (providerFormData.apiEndpointUrl?.trim()) {
494498
try {
495499
const url = new URL(providerFormData.apiEndpointUrl);
496500
if (!['http:', 'https:'].includes(url.protocol)) {
497-
toast('Endpoint URL must use HTTP or HTTPS protocol.');
501+
toast('Endpoint URL must use HTTP or HTTPS protocol.', {
502+
id: VERSIONS_VALIDATION_TOAST_ID,
503+
});
498504
return;
499505
}
500506
} catch {
501507
toast(
502508
'Please enter a valid endpoint URL (e.g., https://api.example.com/v1/chat)'
509+
,{ id: VERSIONS_VALIDATION_TOAST_ID }
503510
);
504511
return;
505512
}
@@ -511,6 +518,7 @@ export default function VersionsPage() {
511518
} catch {
512519
toast(
513520
'Invalid JSON in Request Body Template. Please check the format.'
521+
,{ id: VERSIONS_VALIDATION_TOAST_ID }
514522
);
515523
return;
516524
}
@@ -607,12 +615,12 @@ export default function VersionsPage() {
607615
),
608616
{
609617
onSuccess: () => {
610-
toast('Version updated successfully!');
618+
toast('Version updated successfully!',{id: VERSIONS_ACTION_TOAST_ID});
611619
refetch();
612620
queryClient.invalidateQueries([`fetch_AIModelForPublish_${params.id}`]);
613621
},
614622
onError: (error: any) => {
615-
toast(`Error: ${error.message}`);
623+
toast(`Error: ${error.message}`,{id: VERSIONS_ACTION_TOAST_ID});
616624
},
617625
}
618626
);

app/[locale]/dashboard/[entityType]/[entitySlug]/aimodels/edit/layout.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ const TabsAndChildren = ({ children }: { children: React.ReactNode }) => {
7373
refetchOnReconnect: true,
7474
}
7575
);
76+
const AIMODEL_TITLE_SUCCESS_TOAST_ID = 'aimodel-title-save-success';
77+
const AIMODEL_TITLE_ERROR_TOAST_ID = 'aimodel-title-save-error';
7678

7779
const { mutate, isLoading: editMutationLoading } = useMutation(
7880
(data: { displayName: string }) =>
@@ -90,11 +92,11 @@ const TabsAndChildren = ({ children }: { children: React.ReactNode }) => {
9092
),
9193
{
9294
onSuccess: () => {
93-
toast('AI Model updated successfully');
95+
toast('AI Model updated successfully',{id: AIMODEL_TITLE_SUCCESS_TOAST_ID});
9496
AIModelData.refetch();
9597
},
9698
onError: (error: any) => {
97-
toast(`Error: ${error.message}`);
99+
toast(`Error: ${error.message}`,{id: AIMODEL_TITLE_ERROR_TOAST_ID});
98100
},
99101
}
100102
);

app/[locale]/dashboard/[entityType]/[entitySlug]/aimodels/page.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ const createAIModel: any = graphql(`
5353
}
5454
`);
5555

56+
const AIMODELS_ACTION_TOAST_ID = 'aimodels-list-action-toast';
57+
5658
export default function AIModelsPage({
5759
params,
5860
}: {
@@ -128,11 +130,11 @@ export default function AIModelsPage({
128130
),
129131
{
130132
onSuccess: () => {
131-
toast(`Deleted AI Model successfully`);
133+
toast(`Deleted AI Model successfully`,{id: AIMODELS_ACTION_TOAST_ID});
132134
AllAIModels.refetch();
133135
},
134136
onError: (err: any) => {
135-
toast('Error: ' + err.message.split(':')[0]);
137+
toast('Error: ' + err.message.split(':')[0],{id: AIMODELS_ACTION_TOAST_ID});
136138
},
137139
}
138140
);
@@ -161,13 +163,13 @@ export default function AIModelsPage({
161163
{
162164
onSuccess: (data: any) => {
163165
const newModelId = data.createAiModel.data.id;
164-
toast(`Created AI Model successfully`);
166+
toast(`Created AI Model successfully`,{id: AIMODELS_ACTION_TOAST_ID});
165167
router.push(
166168
`/dashboard/${entityType}/${entitySlug}/aimodels/edit/${newModelId}/details`
167169
);
168170
},
169171
onError: (err: any) => {
170-
toast('Error: ' + err.message.split(':')[0]);
172+
toast('Error: ' + err.message.split(':')[0],{id: AIMODELS_ACTION_TOAST_ID});
171173
},
172174
}
173175
);

app/[locale]/dashboard/[entityType]/[entitySlug]/collaboratives/edit/[id]/assign/page.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const Assign = () => {
4848
id: string;
4949
}>();
5050
const router = useRouter();
51+
const COLLAB_ASSIGN_TOAST_ID = 'collaboratives-assign-toast';
5152

5253
const [data, setData] = useState<any[]>([]); // Ensure `data` is an array
5354
const [selectedRow, setSelectedRows] = useState<any[]>([]);
@@ -126,14 +127,14 @@ const Assign = () => {
126127
),
127128
{
128129
onSuccess: () => {
129-
toast('Dataset Assigned Successfully');
130+
toast('Dataset Assigned Successfully', { id: COLLAB_ASSIGN_TOAST_ID });
130131
CollaborativeDetails.refetch();
131132
router.push(
132133
`/dashboard/${params.entityType}/${params.entitySlug}/collaboratives/edit/${params.id}/usecases`
133134
);
134135
},
135136
onError: (err: any) => {
136-
toast(`Received ${err} on dataset publish `);
137+
toast(`Received ${err} on dataset publish `, { id: COLLAB_ASSIGN_TOAST_ID });
137138
},
138139
}
139140
);

app/[locale]/dashboard/[entityType]/[entitySlug]/collaboratives/edit/[id]/contributors/page.tsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ const Details = () => {
3333
partners: [] as { label: string; value: string }[],
3434
});
3535

36+
const COLLAB_CONTRIBUTORS_TOAST_ID = 'collaboratives-contributors-toast';
37+
3638
const Users: { data: any; isLoading: boolean; refetch: any } = useQuery(
3739
[`fetch_users`],
3840
() =>
@@ -111,11 +113,11 @@ const Details = () => {
111113
}, input),
112114
{
113115
onSuccess: () => {
114-
toast('Contributor added successfully');
116+
toast('Contributor added successfully', { id: COLLAB_CONTRIBUTORS_TOAST_ID });
115117
CollaborativeData.refetch();
116118
},
117119
onError: (error: any) => {
118-
toast(`Error: ${error.message}`);
120+
toast(`Error: ${error.message}`, { id: COLLAB_CONTRIBUTORS_TOAST_ID });
119121
},
120122
}
121123
);
@@ -128,11 +130,11 @@ const Details = () => {
128130
}, input),
129131
{
130132
onSuccess: () => {
131-
toast('Contributor removed successfully');
133+
toast('Contributor removed successfully', { id: COLLAB_CONTRIBUTORS_TOAST_ID });
132134
CollaborativeData.refetch();
133135
},
134136
onError: (error: any) => {
135-
toast(`Error: ${error.message}`);
137+
toast(`Error: ${error.message}`, { id: COLLAB_CONTRIBUTORS_TOAST_ID });
136138
},
137139
}
138140
);
@@ -144,11 +146,11 @@ const Details = () => {
144146
}, input),
145147
{
146148
onSuccess: () => {
147-
toast('Supporter added successfully');
149+
toast('Supporter added successfully', { id: COLLAB_CONTRIBUTORS_TOAST_ID });
148150
CollaborativeData.refetch();
149151
},
150152
onError: (error: any) => {
151-
toast(`Error: ${error.message}`);
153+
toast(`Error: ${error.message}`, { id: COLLAB_CONTRIBUTORS_TOAST_ID });
152154
},
153155
}
154156
);
@@ -161,11 +163,11 @@ const Details = () => {
161163
}, input),
162164
{
163165
onSuccess: () => {
164-
toast('Supporter removed successfully');
166+
toast('Supporter removed successfully', { id: COLLAB_CONTRIBUTORS_TOAST_ID });
165167
CollaborativeData.refetch();
166168
},
167169
onError: (error: any) => {
168-
toast(`Error: ${error.message}`);
170+
toast(`Error: ${error.message}`, { id: COLLAB_CONTRIBUTORS_TOAST_ID });
169171
},
170172
}
171173
);
@@ -177,11 +179,11 @@ const Details = () => {
177179
}, input),
178180
{
179181
onSuccess: () => {
180-
toast('Partner added successfully');
182+
toast('Partner added successfully', { id: COLLAB_CONTRIBUTORS_TOAST_ID });
181183
CollaborativeData.refetch();
182184
},
183185
onError: (error: any) => {
184-
toast(`Error: ${error.message}`);
186+
toast(`Error: ${error.message}`, { id: COLLAB_CONTRIBUTORS_TOAST_ID });
185187
},
186188
}
187189
);
@@ -194,11 +196,11 @@ const Details = () => {
194196
}, input),
195197
{
196198
onSuccess: () => {
197-
toast('Partner removed successfully');
199+
toast('Partner removed successfully', { id: COLLAB_CONTRIBUTORS_TOAST_ID });
198200
CollaborativeData.refetch();
199201
},
200202
onError: (error: any) => {
201-
toast(`Error: ${error.message}`);
203+
toast(`Error: ${error.message}`, { id: COLLAB_CONTRIBUTORS_TOAST_ID });
202204
},
203205
}
204206
);

app/[locale]/dashboard/[entityType]/[entitySlug]/collaboratives/edit/[id]/details/page.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ const Details = () => {
7373
}>();
7474

7575
const router = useRouter();
76+
const COLLAB_DETAILS_TOAST_ID = 'collaboratives-details-toast';
7677

7778
const CollaborativeData: { data: any; isLoading: boolean; refetch: any } = useQuery(
7879
[`fetch_CollaborativeData_details`],
@@ -145,7 +146,7 @@ const Details = () => {
145146
),
146147
{
147148
onSuccess: (res: any) => {
148-
toast('Collaborative updated successfully');
149+
toast('Collaborative updated successfully', { id: COLLAB_DETAILS_TOAST_ID });
149150
setFormData((prev) => ({
150151
...prev,
151152
...res.updateCollaborative,
@@ -156,7 +157,7 @@ const Details = () => {
156157
}));
157158
},
158159
onError: (error: any) => {
159-
toast(`Error: ${error.message}`);
160+
toast(`Error: ${error.message}`, { id: COLLAB_DETAILS_TOAST_ID });
160161
},
161162
}
162163
);

0 commit comments

Comments
 (0)