Commit 6d4db559 authored by janithgamage1.ed's avatar janithgamage1.ed

fix: update

Desc : update project
parent 1e0eff13
...@@ -34,15 +34,15 @@ import { DeleteTwoTone, EditTwoTone, EyeTwoTone, PlusOutlined } from '@ant-desig ...@@ -34,15 +34,15 @@ import { DeleteTwoTone, EditTwoTone, EyeTwoTone, PlusOutlined } from '@ant-desig
//types //types
import { PopupTransition } from 'components/@extended/Transitions'; import { PopupTransition } from 'components/@extended/Transitions';
import curriculumLevels from 'data/curriculumLevels';
import status from 'data/status'; import status from 'data/status';
import AddEditCurriculum from 'sections/parameters/curriculum-management/AddEditCurriculum'; import AddEditCurriculum from 'sections/parameters/curriculum-management/AddEditCurriculum';
import AlertCurriculumDelete from 'sections/parameters/curriculum-management/AlertCurriculumDelete'; import AlertCurriculumDelete from 'sections/parameters/curriculum-management/AlertCurriculumDelete';
import { useDispatch, useSelector } from 'store'; import { useDispatch, useSelector } from 'store';
import { fetchCurriculums, toInitialState } from 'store/reducers/curriculum'; import { fetchCurriculums, toInitialState } from 'store/reducers/curriculum';
import { openSnackbar } from 'store/reducers/snackbar'; import { openSnackbar } from 'store/reducers/snackbar';
import { Curriculums } from 'types/curriculum'; import { Curriculum, Curriculums } from 'types/curriculum';
import { ReactTableProps, curriculumProps } from './types/types'; import { ReactTableProps } from './types/types';
import curriculumLevels from 'data/curriculumLevels';
// ==============================|| REACT TABLE ||============================== // // ==============================|| REACT TABLE ||============================== //
...@@ -142,7 +142,7 @@ const List = () => { ...@@ -142,7 +142,7 @@ const List = () => {
[ [
{ {
Header: '#', Header: '#',
accessor: 'id', accessor: '_id',
className: 'cell-center', className: 'cell-center',
Cell: ({ row }: { row: Row }) => { Cell: ({ row }: { row: Row }) => {
if (row.id === undefined || row.id === null || row.id === '') { if (row.id === undefined || row.id === null || row.id === '') {
...@@ -273,6 +273,7 @@ const List = () => { ...@@ -273,6 +273,7 @@ const List = () => {
onClick={(e: MouseEvent<HTMLButtonElement>) => { onClick={(e: MouseEvent<HTMLButtonElement>) => {
e.stopPropagation(); e.stopPropagation();
setCurriculumId(row.values._id) setCurriculumId(row.values._id)
setCurriculumTitle(row.values.curriculumTitle)
setOpenAlert(true) setOpenAlert(true)
}} }}
> >
...@@ -290,7 +291,7 @@ const List = () => { ...@@ -290,7 +291,7 @@ const List = () => {
//dialog model //dialog model
const [addEdit, setAddEdit] = useState<boolean>(false); const [addEdit, setAddEdit] = useState<boolean>(false);
const [curriculum, setCurriculum] = useState<curriculumProps>(); const [curriculum, setCurriculum] = useState<Curriculum>();
const handleAddEdit = () => { const handleAddEdit = () => {
setAddEdit(!addEdit); setAddEdit(!addEdit);
...@@ -299,7 +300,8 @@ const List = () => { ...@@ -299,7 +300,8 @@ const List = () => {
//alert model //alert model
const [openAlert, setOpenAlert] = useState(false); const [openAlert, setOpenAlert] = useState(false);
const [curriculumId, setCurriculumId] = useState<number | string | undefined>(undefined) const [curriculumId, setCurriculumId] = useState< string | undefined>(undefined)
const [curriculumTitle, setCurriculumTitle] = useState< string | undefined>(undefined)
const handleAlertClose = () => { const handleAlertClose = () => {
setOpenAlert(!openAlert); setOpenAlert(!openAlert);
...@@ -375,10 +377,10 @@ const List = () => { ...@@ -375,10 +377,10 @@ const List = () => {
sx={{ '& .MuiDialog-paper': { p: 0 }, transition: 'transform 225ms' }} sx={{ '& .MuiDialog-paper': { p: 0 }, transition: 'transform 225ms' }}
aria-describedby="alert-dialog-slide-description" aria-describedby="alert-dialog-slide-description"
> >
<AddEditCurriculum curriculum={curriculum} onCancel={handleAddEdit} /> <AddEditCurriculum curriculum={curriculum!} onCancel={handleAddEdit} />
</Dialog> </Dialog>
{/* alert model */} {/* alert model */}
{!curriculum && <AlertCurriculumDelete title={""} open={openAlert} handleClose={handleAlertClose} deleteId={curriculumId} />} {!curriculum && <AlertCurriculumDelete title={curriculumTitle!} open={openAlert} handleClose={handleAlertClose} deleteId={curriculumId} />}
</MainCard> </MainCard>
</> </>
) )
......
import { useState } from 'react'; import { useEffect, useState } from 'react';
// material-ui // material-ui
import { import {
...@@ -33,6 +33,12 @@ import IconButton from 'components/@extended/IconButton'; ...@@ -33,6 +33,12 @@ import IconButton from 'components/@extended/IconButton';
import { DeleteFilled } from '@ant-design/icons'; import { DeleteFilled } from '@ant-design/icons';
import MainCard from 'components/MainCard'; import MainCard from 'components/MainCard';
import curriculumLevels, { CurriculumLevelsType } from 'data/curriculumLevels'; import curriculumLevels, { CurriculumLevelsType } from 'data/curriculumLevels';
import useAuth from 'hooks/useAuth';
import { dispatch, useSelector } from 'store';
import { addCurriculum } from 'store/reducers/curriculum';
import { fetchTutorials } from 'store/reducers/tutorial';
import { Curriculum } from 'types/curriculum';
import { Tutorial } from 'types/tutorial';
import AlertCurriculumDelete from './AlertCurriculumDelete'; import AlertCurriculumDelete from './AlertCurriculumDelete';
// types // types
...@@ -60,25 +66,13 @@ const getInitialValues = (curriculum: FormikValues | null) => { ...@@ -60,25 +66,13 @@ const getInitialValues = (curriculum: FormikValues | null) => {
// ==============================|| CUSTOMER ADD / EDIT ||============================== // // ==============================|| CUSTOMER ADD / EDIT ||============================== //
export interface Props { export interface Props {
curriculum?: { curriculum: Curriculum;
_id: number | string | undefined;
curriculumCode: string;
curriculumLevel: number;
curriculumTitle: string;
curriculumDescription: string;
curriculumImage: string;
tutorials: string[];
status: number;
createdBy: string;
updatedBy: string;
createdAt: Date;
updatedAt: Date;
};
onCancel: () => void; onCancel: () => void;
} }
const AddEditCurriculum = ({ curriculum, onCancel }: Props) => { const AddEditCurriculum = ({ curriculum, onCancel }: Props) => {
const theme = useTheme(); const theme = useTheme();
const { user } = useAuth();
const isCreating = !curriculum; const isCreating = !curriculum;
...@@ -96,11 +90,27 @@ const AddEditCurriculum = ({ curriculum, onCancel }: Props) => { ...@@ -96,11 +90,27 @@ const AddEditCurriculum = ({ curriculum, onCancel }: Props) => {
validationSchema: CurriculumSchema, validationSchema: CurriculumSchema,
enableReinitialize: true, enableReinitialize: true,
onSubmit: (values, { setSubmitting, resetForm }) => { onSubmit: (values, { setSubmitting, resetForm }) => {
console.log(values);
try { try {
if (curriculum) { if (curriculum) {
// PUT API // PUT API
} else { } else {
// POST API // POST API
// const dummyObject: Curriculum = curriculumReqOb
// dispatch(addCurriculum(dummyObject))
const req: Curriculum = {
curriculumCode: values.curriculumCode,
curriculumLevel: values.curriculumLevel!,
curriculumTitle: values.curriculumTitle,
curriculumDescription: values.curriculumDescription,
curriculumImage: values.curriculumImage,
tutorials: values.tutorials!,
createdBy: user?.name!,
};
dispatch(addCurriculum(req))
} }
resetForm() resetForm()
setSubmitting(false); setSubmitting(false);
...@@ -114,6 +124,16 @@ const AddEditCurriculum = ({ curriculum, onCancel }: Props) => { ...@@ -114,6 +124,16 @@ const AddEditCurriculum = ({ curriculum, onCancel }: Props) => {
const { errors, touched, handleSubmit, isSubmitting, getFieldProps, values } = formik; const { errors, touched, handleSubmit, isSubmitting, getFieldProps, values } = formik;
// const { handleSubmit, isSubmitting } = formik; // const { handleSubmit, isSubmitting } = formik;
const { tutorials } = useSelector(state => state.tutorial);
/**
* API Config
* Tutorial API
*/
useEffect(() => {
dispatch(fetchTutorials());
}, [dispatch])
return ( return (
<> <>
<FormikProvider value={formik}> <FormikProvider value={formik}>
...@@ -238,12 +258,12 @@ const AddEditCurriculum = ({ curriculum, onCancel }: Props) => { ...@@ -238,12 +258,12 @@ const AddEditCurriculum = ({ curriculum, onCancel }: Props) => {
<Autocomplete <Autocomplete
fullWidth fullWidth
id={`tutorials.${index}`} id={`tutorials.${index}`}
// value={tutorials.find((option) => option.id === formik.values.curriculumLevel) || null} value={tutorials.find((option) => option._id === formik.values.tutorials[index]) || null}
// onChange={(event: any, newValue: CurriculumLevelsType | null) => { onChange={(event: any, newValue: Tutorial | null) => {
// formik.setFieldValue(`tutorials.${index}`, newValue?.id); formik.setFieldValue(`tutorials.${index}`, newValue?._id);
// }} }}
options={[]} options={tutorials}
// getOptionLabel={(item) => `${item.description}`} getOptionLabel={(item) => `${item.tutorialTitle}`}
renderInput={(params) => { renderInput={(params) => {
return ( return (
<TextField <TextField
......
...@@ -7,20 +7,22 @@ import { PopupTransition } from 'components/@extended/Transitions'; ...@@ -7,20 +7,22 @@ import { PopupTransition } from 'components/@extended/Transitions';
// assets // assets
import { DeleteFilled } from '@ant-design/icons'; import { DeleteFilled } from '@ant-design/icons';
import { useDispatch } from 'store';
import { deleteCurriculum } from 'store/reducers/curriculum';
// types // types
interface Props { interface Props {
title: string; title: string;
open: boolean; open: boolean;
handleClose: (status: boolean) => void; handleClose: (status: boolean) => void;
deleteId: number | string | undefined; deleteId: string | undefined;
} }
// ==============================|| Curriculum - DELETE ||============================== // // ==============================|| Curriculum - DELETE ||============================== //
export default function AlertCurriculumDelete({ title, open, handleClose, deleteId }: Props) { export default function AlertCurriculumDelete({ title, open, handleClose, deleteId }: Props) {
// const dispatch = useDispatch(); const dispatch = useDispatch();
return ( return (
<Dialog <Dialog
...@@ -41,6 +43,14 @@ export default function AlertCurriculumDelete({ title, open, handleClose, delete ...@@ -41,6 +43,14 @@ export default function AlertCurriculumDelete({ title, open, handleClose, delete
<Typography variant="h4" align="center"> <Typography variant="h4" align="center">
Are you sure you want to delete? Are you sure you want to delete?
</Typography> </Typography>
<Typography align="center">
By deleting
<Typography variant="subtitle1" component="span">
{' '}
"{title}"{' '}
</Typography>
Curriculum, Its details & tasks will also be deleted.
</Typography>
</Stack> </Stack>
<Stack direction="row" spacing={2} sx={{ width: 1 }}> <Stack direction="row" spacing={2} sx={{ width: 1 }}>
...@@ -48,7 +58,7 @@ export default function AlertCurriculumDelete({ title, open, handleClose, delete ...@@ -48,7 +58,7 @@ export default function AlertCurriculumDelete({ title, open, handleClose, delete
Cancel Cancel
</Button> </Button>
<Button fullWidth color="error" variant="contained" onClick={() => { <Button fullWidth color="error" variant="contained" onClick={() => {
// dispatch(deleteNutrition(deleteId!)) dispatch(deleteCurriculum(deleteId!))
handleClose(true) handleClose(true)
}} autoFocus> }} autoFocus>
Delete Delete
......
...@@ -71,7 +71,7 @@ const slice = createSlice({ ...@@ -71,7 +71,7 @@ const slice = createSlice({
// DELETE CURRICULUM // DELETE CURRICULUM
deleteCurriculumSuccess(state, action) { deleteCurriculumSuccess(state, action) {
state.curriculums = state.curriculums.filter(curriculum => curriculum._id !== action.payload._id); state.curriculums = state.curriculums.filter(curriculum => curriculum._id !== action.payload);
state.success = "Curriculum deleted successfully." state.success = "Curriculum deleted successfully."
}, },
...@@ -177,7 +177,7 @@ export function updateCurriculum(updatedCurriculum: Curriculum) { ...@@ -177,7 +177,7 @@ export function updateCurriculum(updatedCurriculum: Curriculum) {
* @param curriculumId * @param curriculumId
* @returns * @returns
*/ */
export function deleteCurriculum(curriculumId: number) { export function deleteCurriculum(curriculumId: string) {
return async () => { return async () => {
dispatch(slice.actions.startLoading()); dispatch(slice.actions.startLoading());
......
...@@ -23,11 +23,11 @@ export type Curriculum = { ...@@ -23,11 +23,11 @@ export type Curriculum = {
curriculumTitle: string curriculumTitle: string
curriculumDescription: string curriculumDescription: string
curriculumImage: string curriculumImage: string
curriculumMark: number curriculumMark?: number
tutorials: tutorialType[], tutorials: string[],
status: number status?: number
createdBy: string createdBy: string
createdAt: Date createdAt?: Date
updatedBy?: string updatedBy?: string
updatedAt?: Date updatedAt?: Date
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment