Skip to content

Commit

Permalink
Merge pull request #19 from Aar-if/renamed
Browse files Browse the repository at this point in the history
Issue #PS-1281 feat: Implement the rename facilitator
  • Loading branch information
itsvick authored Jul 18, 2024
2 parents 43a43e6 + 6b613da commit 9d962fe
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components/DeleteUserModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 11 additions & 1 deletion src/components/center/RenameCenterModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,9 +38,12 @@ const RenameCenterModal: React.FC<CreateBlockModalProps> = ({
open,
handleClose,
}) => {
const router = useRouter();
const { t } = useTranslation();
const theme = useTheme<any>();

const { cohortId }: any = router.query;

const [centerName, setCenterName] = useState<string>('');

const handleTextFieldChange = (
Expand All @@ -47,8 +52,13 @@ const RenameCenterModal: React.FC<CreateBlockModalProps> = ({
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();
};
Expand Down
21 changes: 18 additions & 3 deletions src/services/ManageUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -35,7 +35,7 @@ export const assignCentersToFacilitator = async ({
}
};

const updateFacilitator = async (
export const updateFacilitator = async (
userId: string,
userData: FacilitatorDeleteUserData,
): Promise<any> => {
Expand All @@ -51,4 +51,19 @@ const updateFacilitator = async (
}
};

export default updateFacilitator;
export const renameFacilitator = async (
userId: string,
name: string,
): Promise<any> => {
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;
}
};

0 comments on commit 9d962fe

Please sign in to comment.