Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e5f5702

Browse files
authoredJan 25, 2025··
Merge pull request #1066 from chiscookeke11/feat/refactor_AdminService_calls
Feat/refactor admin service calls
2 parents cfd3ceb + c2cc4a9 commit e5f5702

File tree

2 files changed

+366
-362
lines changed

2 files changed

+366
-362
lines changed
 

‎app/admin/quests/create/page.tsx‎

Lines changed: 153 additions & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -259,187 +259,163 @@ export default function Page() {
259259
isSaving.current = true;
260260
setButtonLoading(true);
261261
const unsavedSteps = steps.filter((step) => !step.data.id);
262-
let failedQuestions = [];
262+
263263
for (const step of unsavedSteps) {
264-
if (step.type === "Quiz") {
265-
if (
266-
step.data.quiz_name?.length === 0 ||
267-
step.data.quiz_desc?.length === 0 ||
268-
step.data.quiz_intro?.length === 0 ||
269-
step.data.quiz_cta?.length === 0 ||
270-
step.data.quiz_help_link?.length === 0
271-
) {
272-
showNotification("Please fill all fields for Quiz", "info");
273-
continue;
274-
}
275-
const response = await AdminService.createQuiz({
276-
quest_id: questId,
277-
name: step.data.quiz_name,
278-
desc: step.data.quiz_desc,
279-
intro: step.data.quiz_intro,
280-
cta: step.data.quiz_cta,
281-
help_link: step.data.quiz_help_link,
282-
});
283-
284-
if (response) {
285-
for (const question of step.data.questions) {
286-
try {
287-
await AdminService.createQuizQuestion({
288-
quiz_id: response.quiz_id,
289-
question: question.question,
290-
options: question.options,
291-
correct_answers: question.correct_answers,
292-
});
293-
} catch (error) {
294-
console.error("Error executing promise:", error);
295-
failedQuestions.push(question.question);
264+
try {
265+
let response: any;
266+
switch (step.type) {
267+
case "Quiz":
268+
if (!["quiz_name", "quiz_desc", "quiz_intro", "quiz_cta", "quiz_help_link"]
269+
.every(field => step.data[field]?.length > 0)) {
270+
showNotification("Please fill all fields for Quiz", "info");
271+
continue;
296272
}
297-
}
298-
if (failedQuestions.length > 0) {
299-
showNotification(
300-
`Failed to create ${failedQuestions.length} questions. Please review and try again.`,
301-
"warning"
302-
);
303-
}
304-
step.data.id = response.id;
305-
}
306-
} else if (step.type === "TwitterFw") {
307-
if (
308-
step.data.twfw_name?.length === 0 ||
309-
step.data.twfw_desc?.length === 0 ||
310-
step.data.twfw_username?.length === 0
311-
) {
312-
showNotification(
313-
"Please fill all fields for Twitter Follow",
314-
"info"
315-
);
316-
continue;
317-
}
318-
const response = await AdminService.createTwitterFw({
319-
quest_id: questId,
320-
name: step.data.twfw_name,
321-
desc: step.data.twfw_desc,
322-
username: step.data.twfw_username,
323-
});
324-
if (response) step.data.id = response.id;
325-
} else if (step.type === "TwitterRw") {
326-
if (
327-
step.data.twrw_name?.length === 0 ||
328-
step.data.twrw_desc?.length === 0 ||
329-
step.data.twrw_post_link?.length === 0
330-
) {
331-
showNotification(
332-
"Please fill all fields for Twitter Retweet",
333-
"info"
334-
);
335-
continue;
336-
}
337-
const response = await AdminService.createTwitterRw({
338-
quest_id: questId,
339-
name: step.data.twrw_name,
340-
desc: step.data.twrw_desc,
341-
post_link: step.data.twrw_post_link,
342-
});
343-
if (response) step.data.id = response.id;
344-
} else if (step.type === "Discord") {
345-
if (
346-
step.data.dc_name?.length === 0 ||
347-
step.data.dc_desc?.length === 0 ||
348-
step.data.dc_invite_link?.length === 0 ||
349-
step.data.dc_guild_id?.length === 0
350-
) {
351-
showNotification("Please fill all fields for Discord", "info");
352-
continue;
353-
}
354-
const response = await AdminService.createDiscord({
355-
quest_id: questId,
356-
name: step.data.dc_name,
357-
desc: step.data.dc_desc,
358-
invite_link: step.data.dc_invite_link,
359-
guild_id: step.data.dc_guild_id,
360-
});
361-
if (response) step.data.id = response.id;
362-
} else if (step.type === "Custom") {
363-
if (
364-
step.data.custom_name?.length === 0 ||
365-
step.data.custom_desc?.length === 0 ||
366-
step.data.custom_cta?.length === 0 ||
367-
step.data.custom_href?.length === 0 ||
368-
step.data.custom_api?.length === 0
369-
) {
370-
showNotification("Please fill all fields for Custom", "info");
371-
continue;
372-
}
373-
const response = await AdminService.createCustom({
374-
quest_id: questId,
375-
name: step.data.custom_name,
376-
desc: step.data.custom_desc,
377-
cta: step.data.custom_cta,
378-
href: step.data.custom_href,
379-
api: step.data.custom_api,
380-
});
381-
if (response) step.data.id = response.id;
382-
} else if (step.type === "Domain") {
383-
const response = await AdminService.createDomain({
384-
quest_id: questId,
385-
name: step.data.domain_name,
386-
desc: step.data.domain_desc,
387-
});
388-
if (response) step.data.id = response.id;
389-
} else if (step.type === "Balance") {
390-
try {
391-
const response = await AdminService.createBalance({
392-
quest_id: questId,
393-
name: step.data.balance_name,
394-
desc: step.data.balance_desc,
395-
contracts: step.data.balance_contracts,
396-
cta: step.data.balance_cta,
397-
href: step.data.balance_href,
398-
});
399-
if (response) step.data.id = response.id;
400-
} catch (error) {
401-
console.error("Error while creating balance task:", error);
402-
}
403-
} else if (step.type === "CustomApi") {
404-
try {
405-
const response = await AdminService.createCustomApi({
406-
quest_id: questId,
407-
name: step.data.api_name,
408-
desc: step.data.api_desc,
409-
api_url: step.data.api_url,
410-
cta: step.data.api_cta,
411-
href: step.data.api_href,
412-
regex: step.data.api_regex,
413-
});
414-
if (response) step.data.id = response.id;
415-
} catch (error) {
416-
console.error("Error while creating CustomApi task:", error);
417-
}
418-
} else if (step.type === "Contract") {
419-
try {
420-
const response = await AdminService.createContract({
421-
quest_id: questId,
422-
name: step.data.contract_name,
423-
desc: step.data.contract_desc,
424-
href: step.data.contract_href,
425-
cta: step.data.contract_cta,
426-
calls: (() => {
427-
try {
428-
return JSON.parse(step.data.contract_calls);
429-
} catch (error) {
430-
showNotification("Invalid contract calls format", "error");
431-
throw error;
273+
response = await AdminService.createQuiz({
274+
quest_id: questId,
275+
name: step.data.quiz_name,
276+
desc: step.data.quiz_desc,
277+
intro: step.data.quiz_intro,
278+
cta: step.data.quiz_cta,
279+
help_link: step.data.quiz_help_link,
280+
});
281+
282+
if (response) {
283+
const failedQuestions = await Promise.allSettled(
284+
step.data.questions.map((question: any) =>
285+
AdminService.createQuizQuestion({
286+
quiz_id: response.quiz_id,
287+
question: question.question,
288+
options: question.options,
289+
correct_answers: question.correct_answers,
290+
})
291+
)
292+
).then(results =>
293+
results
294+
.filter((result: any) => result.status === 'rejected')
295+
.map((result: any) => result.reason)
296+
);
297+
298+
if (failedQuestions.length > 0) {
299+
showNotification(
300+
`Failed to create ${failedQuestions.length} questions. Please review and try again.`,
301+
"warning"
302+
);
432303
}
433-
})(),
434-
});
435-
if (response) step.data.id = response.id;
436-
} catch (error) {
437-
console.error("Error while creating contract task:", error);
438-
showNotification(
439-
`Error adding ${step.type} task: ${error}`,
440-
"error"
441-
);
304+
step.data.id = response.id;
305+
}
306+
break;
307+
308+
case "TwitterFw":
309+
if (!["twfw_name", "twfw_desc", "twfw_username"]
310+
.every(field => step.data[field]?.length > 0)) {
311+
showNotification("Please fill all fields for Twitter Follow", "info");
312+
continue;
313+
}
314+
response = await AdminService.createTwitterFw({
315+
quest_id: questId,
316+
name: step.data.twfw_name,
317+
desc: step.data.twfw_desc,
318+
username: step.data.twfw_username,
319+
});
320+
if (response) step.data.id = response.id;
321+
break;
322+
323+
case "TwitterRw":
324+
if (!["twrw_name", "twrw_desc", "twrw_post_link"]
325+
.every(field => step.data[field]?.length > 0)) {
326+
showNotification("Please fill all fields for Twitter Retweet", "info");
327+
continue;
328+
}
329+
response = await AdminService.createTwitterRw({
330+
quest_id: questId,
331+
name: step.data.twrw_name,
332+
desc: step.data.twrw_desc,
333+
post_link: step.data.twrw_post_link,
334+
});
335+
if (response) step.data.id = response.id;
336+
break;
337+
338+
case "Discord":
339+
if (!["dc_name", "dc_desc", "dc_invite_link", "dc_guild_id"]
340+
.every(field => step.data[field]?.length > 0)) {
341+
showNotification("Please fill all fields for Discord", "info");
342+
continue;
343+
}
344+
response = await AdminService.createDiscord({
345+
quest_id: questId,
346+
name: step.data.dc_name,
347+
desc: step.data.dc_desc,
348+
invite_link: step.data.dc_invite_link,
349+
guild_id: step.data.dc_guild_id,
350+
});
351+
if (response) step.data.id = response.id;
352+
break;
353+
354+
case "Custom":
355+
if (!["custom_name", "custom_desc", "custom_cta", "custom_href", "custom_api"]
356+
.every(field => step.data[field]?.length > 0)) {
357+
showNotification("Please fill all fields for Custom", "info");
358+
continue;
359+
}
360+
response = await AdminService.createCustom({
361+
quest_id: questId,
362+
name: step.data.custom_name,
363+
desc: step.data.custom_desc,
364+
cta: step.data.custom_cta,
365+
href: step.data.custom_href,
366+
api: step.data.custom_api,
367+
});
368+
if (response) step.data.id = response.id;
369+
break;
370+
371+
case "Domain":
372+
response = await AdminService.createDomain({
373+
quest_id: questId,
374+
name: step.data.domain_name,
375+
desc: step.data.domain_desc,
376+
});
377+
if (response) step.data.id = response.id;
378+
break;
379+
380+
case "Balance":
381+
response = await AdminService.createBalance({
382+
quest_id: questId,
383+
name: step.data.balance_name,
384+
desc: step.data.balance_desc,
385+
contracts: step.data.balance_contracts,
386+
cta: step.data.balance_cta,
387+
href: step.data.balance_href,
388+
});
389+
if (response) step.data.id = response.id;
390+
break;
391+
392+
case "Contract":
393+
response = await AdminService.createContract({
394+
quest_id: questId,
395+
name: step.data.contract_name,
396+
desc: step.data.contract_desc,
397+
href: step.data.contract_href,
398+
cta: step.data.contract_cta,
399+
calls: JSON.parse(step.data.contract_calls),
400+
});
401+
if (response) step.data.id = response.id;
402+
break;
403+
404+
case "CustomApi":
405+
response = await AdminService.createCustomApi({
406+
quest_id: questId,
407+
name: step.data.api_name,
408+
desc: step.data.api_desc,
409+
api_url: step.data.api_url,
410+
cta: step.data.api_cta,
411+
href: step.data.api_href,
412+
regex: step.data.api_regex,
413+
});
414+
if (response) step.data.id = response.id;
415+
break;
442416
}
417+
} catch (error) {
418+
showNotification(`Error adding ${step.type} task: ${error}`, "error");
443419
}
444420
}
445421
setSteps([...steps]);

‎app/admin/quests/dashboard/[questId]/page.tsx‎

Lines changed: 213 additions & 185 deletions
Original file line numberDiff line numberDiff line change
@@ -483,100 +483,117 @@ const handleTabChange = (pageOrUpdater: SetStateAction<number>) => {
483483
};
484484

485485
const handleAddTasks = useCallback(async (addedTasks: StepMap[]) => {
486-
for (const step of addedTasks) {
486+
const taskPromises = addedTasks.map(async (step) => {
487487
try {
488-
if (step.type === "Quiz") {
489-
await AdminService.createQuiz({
490-
quest_id: questId.current,
491-
name: step.data.quiz_name,
492-
desc: step.data.quiz_desc,
493-
intro: step.data.quiz_intro,
494-
cta: step.data.quiz_cta,
495-
help_link: step.data.quiz_help_link,
496-
});
497-
for (const question of step.data.questions) {
498-
try {
499-
await AdminService.createQuizQuestion({
488+
switch (step.type) {
489+
case "Quiz":
490+
await AdminService.createQuiz({
491+
quest_id: questId.current,
492+
name: step.data.quiz_name,
493+
desc: step.data.quiz_desc,
494+
intro: step.data.quiz_intro,
495+
cta: step.data.quiz_cta,
496+
help_link: step.data.quiz_help_link,
497+
});
498+
499+
const quizQuestionPromises = step.data.questions.map(async (question: any) =>
500+
AdminService.createQuizQuestion({
500501
quiz_id: step.data.quiz_name,
501502
question: question.question,
502503
options: question.options,
503504
correct_answers: question.correct_answers,
504-
});
505-
} catch (error) {
506-
console.error("Error executing promise:", error);
507-
}
508-
}
509-
}
510-
if (step.type === "TwitterFw") {
511-
await AdminService.createTwitterFw({
512-
quest_id: questId.current,
513-
name: step.data.twfw_name,
514-
desc: step.data.twfw_desc,
515-
username: step.data.twfw_username,
516-
});
517-
} else if (step.type === "TwitterRw") {
518-
await AdminService.createTwitterRw({
519-
quest_id: questId.current,
520-
name: step.data.twrw_name,
521-
desc: step.data.twrw_desc,
522-
post_link: step.data.twrw_post_link,
523-
});
524-
} else if (step.type === "Discord") {
525-
await AdminService.createDiscord({
526-
quest_id: questId.current,
527-
name: step.data.dc_name,
528-
desc: step.data.dc_desc,
529-
invite_link: step.data.dc_invite_link,
530-
guild_id: step.data.dc_guild_id,
531-
});
532-
} else if (step.type === "Custom") {
533-
await AdminService.createCustom({
534-
quest_id: questId.current,
535-
name: step.data.custom_name,
536-
desc: step.data.custom_desc,
537-
cta: step.data.custom_cta,
538-
href: step.data.custom_href,
539-
api: step.data.custom_api,
540-
});
541-
} else if (step.type === "Domain") {
542-
await AdminService.createDomain({
543-
quest_id: questId.current,
544-
name: step.data.domain_name,
545-
desc: step.data.domain_desc,
546-
});
547-
} else if (step.type === "Balance") {
548-
await AdminService.createBalance({
549-
quest_id: questId.current,
550-
name: step.data.balance_name,
551-
desc: step.data.balance_desc,
552-
contracts: step.data.balance_contracts,
553-
cta: step.data.balance_cta,
554-
href: step.data.balance_href,
555-
});
556-
} else if (step.type === "Contract") {
557-
await AdminService.createContract({
558-
quest_id: questId.current,
559-
name: step.data.contract_name,
560-
desc: step.data.contract_desc,
561-
href: step.data.contract_href,
562-
cta: step.data.contract_cta,
563-
calls: JSON.parse(step.data.contract_calls),
564-
});
565-
} else if (step.type === "CustomApi") {
566-
await AdminService.createCustomApi({
567-
quest_id: questId.current,
568-
name: step.data.api_name,
569-
desc: step.data.api_desc,
570-
api_url: step.data.api_url,
571-
regex: step.data.api_regex,
572-
href: step.data.api_href,
573-
cta: step.data.api_cta,
574-
});
505+
})
506+
);
507+
await Promise.all(quizQuestionPromises);
508+
break;
509+
510+
case "TwitterFw":
511+
await AdminService.createTwitterFw({
512+
quest_id: questId.current,
513+
name: step.data.twfw_name,
514+
desc: step.data.twfw_desc,
515+
username: step.data.twfw_username,
516+
});
517+
break;
518+
519+
case "TwitterRw":
520+
await AdminService.createTwitterRw({
521+
quest_id: questId.current,
522+
name: step.data.twrw_name,
523+
desc: step.data.twrw_desc,
524+
post_link: step.data.twrw_post_link,
525+
});
526+
break;
527+
528+
case "Discord":
529+
await AdminService.createDiscord({
530+
quest_id: questId.current,
531+
name: step.data.dc_name,
532+
desc: step.data.dc_desc,
533+
invite_link: step.data.dc_invite_link,
534+
guild_id: step.data.dc_guild_id,
535+
});
536+
break;
537+
538+
case "Custom":
539+
await AdminService.createCustom({
540+
quest_id: questId.current,
541+
name: step.data.custom_name,
542+
desc: step.data.custom_desc,
543+
cta: step.data.custom_cta,
544+
href: step.data.custom_href,
545+
api: step.data.custom_api,
546+
});
547+
break;
548+
549+
case "Domain":
550+
await AdminService.createDomain({
551+
quest_id: questId.current,
552+
name: step.data.domain_name,
553+
desc: step.data.domain_desc,
554+
});
555+
break;
556+
557+
case "Balance":
558+
await AdminService.createBalance({
559+
quest_id: questId.current,
560+
name: step.data.balance_name,
561+
desc: step.data.balance_desc,
562+
contracts: step.data.balance_contracts,
563+
cta: step.data.balance_cta,
564+
href: step.data.balance_href,
565+
});
566+
break;
567+
568+
case "Contract":
569+
await AdminService.createContract({
570+
quest_id: questId.current,
571+
name: step.data.contract_name,
572+
desc: step.data.contract_desc,
573+
href: step.data.contract_href,
574+
cta: step.data.contract_cta,
575+
calls: JSON.parse(step.data.contract_calls),
576+
});
577+
break;
578+
579+
case "CustomApi":
580+
await AdminService.createCustomApi({
581+
quest_id: questId.current,
582+
name: step.data.api_name,
583+
desc: step.data.api_desc,
584+
api_url: step.data.api_url,
585+
regex: step.data.api_regex,
586+
href: step.data.api_href,
587+
cta: step.data.api_cta,
588+
});
589+
break;
575590
}
576591
} catch (error) {
577592
showNotification(`Error adding ${step.type} task: ${error}`, "error");
578593
}
579-
}
594+
});
595+
596+
await Promise.all(taskPromises);
580597
}, []);
581598

582599
const handleDeleteTasks = useCallback(async (removedTasks: StepMap[]) => {
@@ -591,114 +608,125 @@ const handleTabChange = (pageOrUpdater: SetStateAction<number>) => {
591608

592609
const handleUpdateTasks = useCallback(async (updatedSteps: StepMap[]) => {
593610
const taskPromises = updatedSteps.map(async (step) => {
594-
if (step.type === "Quiz") {
595-
await AdminService.updateQuiz({
596-
id: step.data.id,
597-
name: step.data.quiz_name,
598-
desc: step.data.quiz_desc,
599-
intro: step.data.quiz_intro,
600-
cta: step.data.quiz_cta,
601-
help_link: step.data.quiz_help_link,
602-
quiz_id: step.data.quiz_id,
603-
});
604-
605-
for (const question of step.data.questions) {
606-
try {
607-
if (question.id === 0) {
608-
await AdminService.createQuizQuestion({
609-
quiz_id: step.data.quiz_id,
611+
try {
612+
switch (step.type) {
613+
case "Quiz":
614+
await AdminService.updateQuiz({
615+
id: step.data.id,
616+
name: step.data.quiz_name,
617+
desc: step.data.quiz_desc,
618+
intro: step.data.quiz_intro,
619+
cta: step.data.quiz_cta,
620+
help_link: step.data.quiz_help_link,
621+
quiz_id: step.data.quiz_id,
622+
});
623+
624+
const quizQuestionPromises = step.data.questions.map(async (question: any) => {
625+
if (question.id === 0) {
626+
await AdminService.createQuizQuestion({
627+
quiz_id: step.data.quiz_id,
628+
question: question.question,
629+
options: question.options,
630+
correct_answers: question.correct_answers,
631+
});
632+
}
633+
return AdminService.updateQuizQuestion({
634+
id: question.id,
610635
question: question.question,
611636
options: question.options,
612637
correct_answers: question.correct_answers,
638+
quiz_id: step.data.quiz_id,
613639
});
614-
}
615-
await AdminService.updateQuizQuestion({
616-
id: question.id,
617-
question: question.question,
618-
options: question.options,
619-
correct_answers: question.correct_answers,
620-
quiz_id: step.data.quiz_id,
621640
});
622-
} catch (error) {
623-
console.error("Error executing promise:", error);
624-
}
625-
}
626-
}
627-
if (step.type === "TwitterFw") {
628-
await AdminService.updateTwitterFw({
629-
id: step.data.id,
630-
name: step.data.twfw_name,
631-
desc: step.data.twfw_desc,
632-
username: step.data.twfw_username,
633-
});
634-
} else if (step.type === "TwitterRw") {
635-
await AdminService.updateTwitterRw({
636-
id: step.data.id,
637-
name: step.data.twrw_name,
638-
desc: step.data.twrw_desc,
639-
post_link: step.data.twrw_post_link,
640-
});
641-
} else if (step.type === "Discord") {
642-
await AdminService.updateDiscord({
643-
id: step.data.id,
644-
name: step.data.dc_name,
645-
desc: step.data.dc_desc,
646-
invite_link: step.data.dc_invite_link,
647-
guild_id: step.data.dc_guild_id,
648-
});
649-
} else if (step.type === "Custom") {
650-
await AdminService.updateCustom({
651-
id: step.data.id,
652-
name: step.data.custom_name,
653-
desc: step.data.custom_desc,
654-
cta: step.data.custom_cta,
655-
href: step.data.custom_href,
656-
api: step.data.custom_api,
657-
});
658-
} else if (step.type === "Domain") {
659-
await AdminService.updateDomain({
660-
id: step.data.id,
661-
name: step.data.custom_name,
662-
desc: step.data.custom_desc,
663-
});
664-
} else if (step.type === "Balance") {
665-
await AdminService.updateBalance({
666-
id: step.data.id,
667-
name: step.data.balance_name,
668-
desc: step.data.balance_desc,
669-
contracts: step.data.balance_contracts,
670-
cta: step.data.balance_cta,
671-
href: step.data.balance_href,
672-
});
673-
} else if (step.type === "Contract") {
674-
try {
675-
await AdminService.updateContract({
676-
id: step.data.id,
677-
name: step.data.contract_name,
678-
desc: step.data.contract_desc,
679-
href: step.data.contract_href,
680-
cta: step.data.contract_cta,
681-
calls: JSON.parse(step.data.contract_calls),
682-
});
683-
} catch (error) {
684-
showNotification(
685-
`Error updating ${step.type} task: ${error}`,
686-
"error"
687-
);
641+
await Promise.all(quizQuestionPromises);
642+
break;
643+
644+
case "TwitterFw":
645+
await AdminService.updateTwitterFw({
646+
id: step.data.id,
647+
name: step.data.twfw_name,
648+
desc: step.data.twfw_desc,
649+
username: step.data.twfw_username,
650+
});
651+
break;
652+
653+
case "TwitterRw":
654+
await AdminService.updateTwitterRw({
655+
id: step.data.id,
656+
name: step.data.twrw_name,
657+
desc: step.data.twrw_desc,
658+
post_link: step.data.twrw_post_link,
659+
});
660+
break;
661+
662+
case "Discord":
663+
await AdminService.updateDiscord({
664+
id: step.data.id,
665+
name: step.data.dc_name,
666+
desc: step.data.dc_desc,
667+
invite_link: step.data.dc_invite_link,
668+
guild_id: step.data.dc_guild_id,
669+
});
670+
break;
671+
672+
case "Custom":
673+
await AdminService.updateCustom({
674+
id: step.data.id,
675+
name: step.data.custom_name,
676+
desc: step.data.custom_desc,
677+
cta: step.data.custom_cta,
678+
href: step.data.custom_href,
679+
api: step.data.custom_api,
680+
});
681+
break;
682+
683+
case "Domain":
684+
await AdminService.updateDomain({
685+
id: step.data.id,
686+
name: step.data.custom_name,
687+
desc: step.data.custom_desc,
688+
});
689+
break;
690+
691+
case "Balance":
692+
await AdminService.updateBalance({
693+
id: step.data.id,
694+
name: step.data.balance_name,
695+
desc: step.data.balance_desc,
696+
contracts: step.data.balance_contracts,
697+
cta: step.data.balance_cta,
698+
href: step.data.balance_href,
699+
});
700+
break;
701+
702+
case "Contract":
703+
await AdminService.updateContract({
704+
id: step.data.id,
705+
name: step.data.contract_name,
706+
desc: step.data.contract_desc,
707+
href: step.data.contract_href,
708+
cta: step.data.contract_cta,
709+
calls: JSON.parse(step.data.contract_calls),
710+
});
711+
break;
712+
713+
case "CustomApi":
714+
await AdminService.updateCustomApi({
715+
id: step.data.id,
716+
name: step.data.api_name,
717+
desc: step.data.api_desc,
718+
api_url: step.data.api_url,
719+
cta: step.data.api_cta,
720+
href: step.data.api_href,
721+
regex: step.data.api_regex,
722+
});
723+
break;
688724
}
689-
} else if (step.type === "CustomApi") {
690-
await AdminService.updateCustomApi({
691-
id: step.data.id,
692-
name: step.data.api_name,
693-
desc: step.data.api_desc,
694-
api_url: step.data.api_url,
695-
cta: step.data.api_cta,
696-
href: step.data.api_href,
697-
regex: step.data.api_regex,
698-
});
725+
} catch (error) {
726+
showNotification(`Error updating ${step.type} task: ${error}`, "error");
699727
}
700728
});
701-
729+
702730
await Promise.all(taskPromises);
703731
}, []);
704732

0 commit comments

Comments
 (0)
Please sign in to comment.