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