From 4f0fb469b79cc4586dffb0d3444b79dfc5645787 Mon Sep 17 00:00:00 2001 From: Akshata Katwal Date: Thu, 14 Nov 2024 16:23:21 +0530 Subject: [PATCH] Issue feat PS-2485:Add error message on duplicate center name --- public/locales/en/common.json | 3 ++- src/components/AddNewCenters.tsx | 2 +- src/services/CohortService/cohortService.ts | 19 ++++++++++++++++--- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 726a4dd4..df586d69 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -137,7 +137,8 @@ "ASSIGNED_TEAM_LEADERS":"{{assignedTeamLeaderNames}} and more..", "CONTINUE":"Continue", "DESCRIPTION": "Description", - "PAGE_NOT_FOUND": "Page Not Found" + "PAGE_NOT_FOUND": "Page Not Found", + "ALREADY_EXIST":"Cohort name already exist.Please provide another name" }, "LOGIN_PAGE": { "USERNAME": "Username", diff --git a/src/components/AddNewCenters.tsx b/src/components/AddNewCenters.tsx index 864b3f0d..e5a75d22 100644 --- a/src/components/AddNewCenters.tsx +++ b/src/components/AddNewCenters.tsx @@ -225,7 +225,7 @@ const AddNewCenters: React.FC = ({ ).values() ); - const cohortData = await createCohort(cohortDetails); + const cohortData = await createCohort(cohortDetails, t); if (cohortData) { showToastMessage(t("CENTERS.CENTER_CREATED_SUCCESSFULLY"), "success"); const windowUrl = window.location.pathname; diff --git a/src/services/CohortService/cohortService.ts b/src/services/CohortService/cohortService.ts index 70ff766a..761be7b8 100644 --- a/src/services/CohortService/cohortService.ts +++ b/src/services/CohortService/cohortService.ts @@ -1,5 +1,8 @@ import { CohortMemberList } from "@/utils/Interfaces"; import { get, post, put } from "../RestClient"; +import axios from 'axios'; +import { showToastMessage } from "@/components/Toastify"; +import { useTranslation } from "next-i18next"; export interface cohortListFilter { type: string; @@ -81,16 +84,26 @@ export const createUser = async (userData: any): Promise => { } }; -export const createCohort = async (userData: any): Promise => { +export const createCohort = async (userData: any, t?:any): Promise => { const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/cohort/create`; + try { + const response = await post(apiUrl, userData); return response?.data; } catch (error) { console.error("error in getting cohort list", error); - // throw error; + + if (axios.isAxiosError(error) && error.response) { + if (error.response.status === 409) { + showToastMessage(t("COMMON.ALREADY_EXIST"), "info"); + + + } + else + throw error; } -}; +}}; export const fetchCohortMemberList = async ({ limit,