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,