From 6b613da7a635016f1f660ba99698f4ca19d3f747 Mon Sep 17 00:00:00 2001 From: Arif Date: Thu, 18 Jul 2024 17:16:37 +0530 Subject: [PATCH] Issue #PS-1281 feat: Implement the delete facilitator --- src/components/DeleteUserModal.tsx | 2 +- src/components/center/RenameCenterModal.tsx | 12 +++++++++++- src/services/ManageUser.ts | 21 ++++++++++++++++++--- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/components/DeleteUserModal.tsx b/src/components/DeleteUserModal.tsx index 1a847fd4..7f1fb656 100644 --- a/src/components/DeleteUserModal.tsx +++ b/src/components/DeleteUserModal.tsx @@ -18,7 +18,7 @@ import CloseIcon from '@mui/icons-material/Close'; import { showToastMessage } from './Toastify'; import manageUserStore from '@/store/manageUserStore'; import { getCohortList } from '@/services/CohortServices'; -import updateFacilitator from '@/services/ManageUser'; +import { updateFacilitator } from '@/services/ManageUser'; interface DeleteUserModalProps { deleteFacilitatorId: string; diff --git a/src/components/center/RenameCenterModal.tsx b/src/components/center/RenameCenterModal.tsx index c0a8915a..7204a65a 100644 --- a/src/components/center/RenameCenterModal.tsx +++ b/src/components/center/RenameCenterModal.tsx @@ -19,6 +19,8 @@ import { useTranslation } from 'next-i18next'; import { serverSideTranslations } from 'next-i18next/serverSideTranslations'; import { useTheme, styled } from '@mui/material/styles'; import { showToastMessage } from '../Toastify'; +import { renameFacilitator } from '@/services/ManageUser'; +import { useRouter } from 'next/router'; interface CreateBlockModalProps { open: boolean; @@ -36,9 +38,12 @@ const RenameCenterModal: React.FC = ({ open, handleClose, }) => { + const router = useRouter(); const { t } = useTranslation(); const theme = useTheme(); + const { cohortId }: any = router.query; + const [centerName, setCenterName] = useState(''); const handleTextFieldChange = ( @@ -47,8 +52,13 @@ const RenameCenterModal: React.FC = ({ setCenterName(event.target.value); }; - const handleCreateButtonClick = () => { + const handleCreateButtonClick = async () => { console.log('Entered Rename Name:', centerName); + + const name = centerName; + + const response = await renameFacilitator(cohortId, name); + showToastMessage(t('CENTERS.CENTER_RENAMED'), 'success'); handleClose(); }; diff --git a/src/services/ManageUser.ts b/src/services/ManageUser.ts index a9b7182c..d5ffd243 100644 --- a/src/services/ManageUser.ts +++ b/src/services/ManageUser.ts @@ -4,7 +4,7 @@ import { FacilitatorListParam, UserData, } from '@/utils/Interfaces'; -import { patch, post } from './RestClient'; +import { patch, post, put } from './RestClient'; export const getFacilitatorList = async ({ limit, @@ -35,7 +35,7 @@ export const assignCentersToFacilitator = async ({ } }; -const updateFacilitator = async ( +export const updateFacilitator = async ( userId: string, userData: FacilitatorDeleteUserData, ): Promise => { @@ -51,4 +51,19 @@ const updateFacilitator = async ( } }; -export default updateFacilitator; +export const renameFacilitator = async ( + userId: string, + name: string, +): Promise => { + const apiUrl = `${process.env.NEXT_PUBLIC_BASE_URL}/cohort/update/${userId}`; + try { + const response = await put( + apiUrl,{ name } + ); + return response.data.result; + } catch (error) { + console.error('Error in updating Facilitator', error); + throw error; + } +}; +