Commit 93fc9979 authored by janithgamage1.ed's avatar janithgamage1.ed

fix: update

Desc : update project
parent a6b843b5
import { tutorialType } from "types/tutorial"; import { Tutorial, tutorialType } from "types/tutorial";
export const tutorials: tutorialType[] = [ export const tutorials: tutorialType[] = [
{ {
...@@ -180,4 +180,23 @@ export const tutorials: tutorialType[] = [ ...@@ -180,4 +180,23 @@ export const tutorials: tutorialType[] = [
"createdAt": new Date("2023-08-30T12:00:00Z"), "createdAt": new Date("2023-08-30T12:00:00Z"),
"tutorialMark": 0, "tutorialMark": 0,
} }
] ]
\ No newline at end of file
export const tutorialReqOb: Tutorial = {
"tutorialCode": "Tutorial Code -12312",
"tutorialTitle": "Tutorial Title",
"tutorialImage": "Tutorial Image",
"tutorialDescription": "Tutorial Description",
"taskItems": [
{
"title": "Task Title -213123",
"description": "Task Reference Image",
//@ts-ignore
"howToDo": "Task How To Do",
"referenceImage": "Task Reference Image",
"referenceVideo": "Task Reference Image",
"taskItemMark": 10
}
],
"createdBy": "Nuwan Gamage"
}
\ No newline at end of file
...@@ -40,8 +40,8 @@ import AlertTutorialDelete from 'sections/parameters/tutorial-management/AlertTu ...@@ -40,8 +40,8 @@ import AlertTutorialDelete from 'sections/parameters/tutorial-management/AlertTu
import { useDispatch, useSelector } from 'store'; import { useDispatch, useSelector } from 'store';
import { openSnackbar } from 'store/reducers/snackbar'; import { openSnackbar } from 'store/reducers/snackbar';
import { fetchTutorials, toInitialState } from 'store/reducers/tutorial'; import { fetchTutorials, toInitialState } from 'store/reducers/tutorial';
import { Tutorials } from 'types/tutorial'; import { Tutorial, Tutorials } from 'types/tutorial';
import { ReactTableProps, tutorialProps } from './types/types'; import { ReactTableProps } from './types/types';
// ==============================|| REACT TABLE ||============================== // // ==============================|| REACT TABLE ||============================== //
...@@ -396,7 +396,7 @@ const List = () => { ...@@ -396,7 +396,7 @@ const List = () => {
//dialog model //dialog model
const [addEdit, setAddEdit] = useState<boolean>(false); const [addEdit, setAddEdit] = useState<boolean>(false);
const [tutorial, setTutorial] = useState<tutorialProps>(); const [tutorial, setTutorial] = useState<Tutorial>();
const handleAddEdit = () => { const handleAddEdit = () => {
setAddEdit(!addEdit); setAddEdit(!addEdit);
...@@ -481,7 +481,7 @@ const List = () => { ...@@ -481,7 +481,7 @@ 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"
> >
<AddEditTutorial tutorial={tutorial} onCancel={handleAddEdit} /> <AddEditTutorial tutorial={tutorial!} onCancel={handleAddEdit} />
</Dialog> </Dialog>
{/* alert model */} {/* alert model */}
{!tutorial && <AlertTutorialDelete title={""} open={openAlert} handleClose={handleAlertClose} deleteId={tutorialId} />} {!tutorial && <AlertTutorialDelete title={""} open={openAlert} handleClose={handleAlertClose} deleteId={tutorialId} />}
......
...@@ -32,6 +32,10 @@ import IconButton from 'components/@extended/IconButton'; ...@@ -32,6 +32,10 @@ import IconButton from 'components/@extended/IconButton';
import { DeleteFilled } from '@ant-design/icons'; import { DeleteFilled } from '@ant-design/icons';
import { AccordionSummary, InputLabel, TextField } from '@mui/material'; import { AccordionSummary, InputLabel, TextField } from '@mui/material';
import MainCard from 'components/MainCard'; import MainCard from 'components/MainCard';
import { tutorialReqOb } from 'data/tutorials';
import { dispatch } from 'store';
import { addTutorial } from 'store/reducers/tutorial';
import { Tutorial } from 'types/tutorial';
import AlertTutorialDelete from './AlertTutorialDelete'; import AlertTutorialDelete from './AlertTutorialDelete';
// types // types
...@@ -53,6 +57,7 @@ const getInitialValues = (tutorial: FormikValues | null) => { ...@@ -53,6 +57,7 @@ const getInitialValues = (tutorial: FormikValues | null) => {
howToDo: "", howToDo: "",
referenceImage: "", referenceImage: "",
referenceVideo: "", referenceVideo: "",
taskItemMark: 0,
} }
] ]
} }
...@@ -67,37 +72,36 @@ const getInitialValues = (tutorial: FormikValues | null) => { ...@@ -67,37 +72,36 @@ const getInitialValues = (tutorial: FormikValues | null) => {
// ==============================|| CUSTOMER ADD / EDIT ||============================== // // ==============================|| CUSTOMER ADD / EDIT ||============================== //
export interface Props { export interface Props {
tutorial?: { tutorial?: Tutorial
_id: number | string | undefined
tutorialCode: string;
tutorialTitle: string;
tutorialDescription: string;
tutorialImage: string;
status: number;
createdBy: string;
updatedBy: string;
createdAt: Date;
updatedAt: Date;
taskItems: taskItemProps[]
};
onCancel: () => void; onCancel: () => void;
} }
export interface taskItemProps {
_id: number | string | undefined;
title: string;
description: string;
howToDo: string;
referenceImage: string;
referenceVideo: string;
}
const AddEditTutorial = ({ tutorial, onCancel }: Props) => { const AddEditTutorial = ({ tutorial, onCancel }: Props) => {
const theme = useTheme(); const theme = useTheme();
const isCreating = !tutorial; const isCreating = !tutorial;
const TutorialSchema = Yup.object().shape({}); const TutorialSchema = Yup.object().shape({
// tutorialCode: Yup.string().required(`Tutorial Code is required`),
// tutorialTitle: Yup.string().required(`Tutorial Title is required`),
// tutorialDescription: Yup.string().required(`Tutorial Description is required`),
// tutorialImage: Yup.string().required(`Tutorial Image Ref is required`),
// taskItems: Yup.array().of(
// Yup.object().shape({
// title: Yup.string().required(`Task Title is required`),
// description: Yup.string().required(`Task Description is required`),
// howToDo: Yup.string().required(`Task How To Do is required`),
// referenceImage: Yup.string().required(`Task Reference Image is required`),
// referenceVideo: Yup.string(),
// taskItemMark: Yup.number().required(`Task Mark is required`).min(1, 'Task Mark must be greater than 0'),
// })
// ).required(`Tutorial Task Item is required`),
// status: Yup.number(),
// createdBy: Yup.string(),
// createdAt: Yup.date(),
// updatedBy: Yup.string(),
// updatedAt: Yup.date(),
});
const [openAlert, setOpenAlert] = useState(false); const [openAlert, setOpenAlert] = useState(false);
...@@ -115,7 +119,13 @@ const AddEditTutorial = ({ tutorial, onCancel }: Props) => { ...@@ -115,7 +119,13 @@ const AddEditTutorial = ({ tutorial, onCancel }: Props) => {
if (tutorial) { if (tutorial) {
// PUT API // PUT API
} else { } else {
// POST API // POST API
//@ts-ignore
// const req: Tutorial = { ...values }
const sampleReq: Tutorial = tutorialReqOb
//@ts-ignore
dispatch(addTutorial(sampleReq))
} }
resetForm() resetForm()
setSubmitting(false); setSubmitting(false);
...@@ -266,7 +276,7 @@ const AddEditTutorial = ({ tutorial, onCancel }: Props) => { ...@@ -266,7 +276,7 @@ const AddEditTutorial = ({ tutorial, onCancel }: Props) => {
</AccordionSummary> </AccordionSummary>
<AccordionDetails> <AccordionDetails>
<Grid container spacing={2}> <Grid container spacing={2}>
<Grid item xs={12}> <Grid item xs={6}>
<Stack spacing={1.25}> <Stack spacing={1.25}>
<InputLabel htmlFor={`taskItems.${index}.title`}>Task Title</InputLabel> <InputLabel htmlFor={`taskItems.${index}.title`}>Task Title</InputLabel>
<TextField <TextField
...@@ -274,8 +284,37 @@ const AddEditTutorial = ({ tutorial, onCancel }: Props) => { ...@@ -274,8 +284,37 @@ const AddEditTutorial = ({ tutorial, onCancel }: Props) => {
id={`taskItems.${index}.title`} id={`taskItems.${index}.title`}
placeholder="Enter Task Title" placeholder="Enter Task Title"
{...getFieldProps(`taskItems.${index}.title`)} {...getFieldProps(`taskItems.${index}.title`)}
// error={Boolean(touched.ingredientNutritions![index].nutritionCategory && errors.ingredientNutritions![index].nutritionCategory)} error={Boolean(
// helperText={touched.ingredientNutritions![index].nutritionCategory && errors.ingredientNutritions![index].nutritionCategory} touched.taskItems && touched.taskItems[index].title &&
//@ts-ignore
errors.taskItems && errors.taskItems[index] && errors.taskItems[index].title
)}
helperText={
touched.taskItems && touched.taskItems[index].title &&
//@ts-ignore
errors.taskItems && errors.taskItems[index] && errors.taskItems[index].title
}
/>
</Stack>
</Grid>
<Grid item xs={6}>
<Stack spacing={1.25}>
<InputLabel htmlFor={`taskItems.${index}.taskItemMark`}>Task Mark</InputLabel>
<TextField
fullWidth
id={`taskItems.${index}.taskItemMark`}
placeholder="Enter Task Mark"
{...getFieldProps(`taskItems.${index}.taskItemMark`)}
error={Boolean(
touched.taskItems && touched.taskItems[index].taskItemMark &&
//@ts-ignore
errors.taskItems && errors.taskItems[index] && errors.taskItems[index].taskItemMark
)}
helperText={
touched.taskItems && touched.taskItems[index].taskItemMark &&
//@ts-ignore
errors.taskItems && errors.taskItems[index] && errors.taskItems[index].taskItemMark
}
/> />
</Stack> </Stack>
</Grid> </Grid>
...@@ -287,8 +326,16 @@ const AddEditTutorial = ({ tutorial, onCancel }: Props) => { ...@@ -287,8 +326,16 @@ const AddEditTutorial = ({ tutorial, onCancel }: Props) => {
id={`taskItems.${index}.referenceImage`} id={`taskItems.${index}.referenceImage`}
placeholder="Enter Task Reference Image" placeholder="Enter Task Reference Image"
{...getFieldProps(`taskItems.${index}.referenceImage`)} {...getFieldProps(`taskItems.${index}.referenceImage`)}
// error={Boolean(touched.ingredientNutritions![index].nutritionCategory && errors.ingredientNutritions![index].nutritionCategory)} error={Boolean(
// helperText={touched.ingredientNutritions![index].nutritionCategory && errors.ingredientNutritions![index].nutritionCategory} touched.taskItems && touched.taskItems[index].referenceImage &&
//@ts-ignore
errors.taskItems && errors.taskItems[index] && errors.taskItems[index].referenceImage
)}
helperText={
touched.taskItems && touched.taskItems[index].referenceImage &&
//@ts-ignore
errors.taskItems && errors.taskItems[index] && errors.taskItems[index].referenceImage
}
/> />
</Stack> </Stack>
</Grid> </Grid>
...@@ -300,8 +347,16 @@ const AddEditTutorial = ({ tutorial, onCancel }: Props) => { ...@@ -300,8 +347,16 @@ const AddEditTutorial = ({ tutorial, onCancel }: Props) => {
id={`taskItems.${index}.referenceVideo`} id={`taskItems.${index}.referenceVideo`}
placeholder="Enter Task Reference Video" placeholder="Enter Task Reference Video"
{...getFieldProps(`taskItems.${index}.referenceVideo`)} {...getFieldProps(`taskItems.${index}.referenceVideo`)}
// error={Boolean(touched.ingredientNutritions![index].nutritionCategory && errors.ingredientNutritions![index].nutritionCategory)} error={Boolean(
// helperText={touched.ingredientNutritions![index].nutritionCategory && errors.ingredientNutritions![index].nutritionCategory} touched.taskItems && touched.taskItems[index].referenceVideo &&
//@ts-ignore
errors.taskItems && errors.taskItems[index] && errors.taskItems[index].referenceVideo
)}
helperText={
touched.taskItems && touched.taskItems[index].referenceVideo &&
//@ts-ignore
errors.taskItems && errors.taskItems[index] && errors.taskItems[index].referenceVideo
}
/> />
</Stack> </Stack>
</Grid> </Grid>
...@@ -313,8 +368,16 @@ const AddEditTutorial = ({ tutorial, onCancel }: Props) => { ...@@ -313,8 +368,16 @@ const AddEditTutorial = ({ tutorial, onCancel }: Props) => {
id={`taskItems.${index}.description`} id={`taskItems.${index}.description`}
placeholder="Enter Task Description" placeholder="Enter Task Description"
{...getFieldProps(`taskItems.${index}.description`)} {...getFieldProps(`taskItems.${index}.description`)}
// error={Boolean(touched.ingredientNutritions![index].nutritionCategory && errors.ingredientNutritions![index].nutritionCategory)} error={Boolean(
// helperText={touched.ingredientNutritions![index].nutritionCategory && errors.ingredientNutritions![index].nutritionCategory} touched.taskItems && touched.taskItems[index].description &&
//@ts-ignore
errors.taskItems && errors.taskItems[index] && errors.taskItems[index].description
)}
helperText={
touched.taskItems && touched.taskItems[index].description &&
//@ts-ignore
errors.taskItems && errors.taskItems[index] && errors.taskItems[index].description
}
/> />
</Stack> </Stack>
</Grid> </Grid>
...@@ -326,8 +389,16 @@ const AddEditTutorial = ({ tutorial, onCancel }: Props) => { ...@@ -326,8 +389,16 @@ const AddEditTutorial = ({ tutorial, onCancel }: Props) => {
id={`taskItems.${index}.howToDo`} id={`taskItems.${index}.howToDo`}
placeholder="Enter Task How To Do" placeholder="Enter Task How To Do"
{...getFieldProps(`taskItems.${index}.howToDo`)} {...getFieldProps(`taskItems.${index}.howToDo`)}
// error={Boolean(touched.ingredientNutritions![index].nutritionCategory && errors.ingredientNutritions![index].nutritionCategory)} error={Boolean(
// helperText={touched.ingredientNutritions![index].nutritionCategory && errors.ingredientNutritions![index].nutritionCategory} touched.taskItems && touched.taskItems[index].howToDo &&
//@ts-ignore
errors.taskItems && errors.taskItems[index] && errors.taskItems[index].howToDo
)}
helperText={
touched.taskItems && touched.taskItems[index].howToDo &&
//@ts-ignore
errors.taskItems && errors.taskItems[index] && errors.taskItems[index].howToDo
}
/> />
</Stack> </Stack>
</Grid> </Grid>
......
...@@ -21,11 +21,11 @@ export type Tutorial = { ...@@ -21,11 +21,11 @@ export type Tutorial = {
tutorialTitle?: string tutorialTitle?: string
tutorialDescription?: string tutorialDescription?: string
tutorialImage?: string tutorialImage?: string
tutorialMark: number tutorialMark?: number
taskItems: taskItemType[] taskItems: taskItemType[]
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