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[] = [
{
......@@ -180,4 +180,23 @@ export const tutorials: tutorialType[] = [
"createdAt": new Date("2023-08-30T12:00:00Z"),
"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
import { useDispatch, useSelector } from 'store';
import { openSnackbar } from 'store/reducers/snackbar';
import { fetchTutorials, toInitialState } from 'store/reducers/tutorial';
import { Tutorials } from 'types/tutorial';
import { ReactTableProps, tutorialProps } from './types/types';
import { Tutorial, Tutorials } from 'types/tutorial';
import { ReactTableProps } from './types/types';
// ==============================|| REACT TABLE ||============================== //
......@@ -396,7 +396,7 @@ const List = () => {
//dialog model
const [addEdit, setAddEdit] = useState<boolean>(false);
const [tutorial, setTutorial] = useState<tutorialProps>();
const [tutorial, setTutorial] = useState<Tutorial>();
const handleAddEdit = () => {
setAddEdit(!addEdit);
......@@ -481,7 +481,7 @@ const List = () => {
sx={{ '& .MuiDialog-paper': { p: 0 }, transition: 'transform 225ms' }}
aria-describedby="alert-dialog-slide-description"
>
<AddEditTutorial tutorial={tutorial} onCancel={handleAddEdit} />
<AddEditTutorial tutorial={tutorial!} onCancel={handleAddEdit} />
</Dialog>
{/* alert model */}
{!tutorial && <AlertTutorialDelete title={""} open={openAlert} handleClose={handleAlertClose} deleteId={tutorialId} />}
......
......@@ -32,6 +32,10 @@ import IconButton from 'components/@extended/IconButton';
import { DeleteFilled } from '@ant-design/icons';
import { AccordionSummary, InputLabel, TextField } from '@mui/material';
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';
// types
......@@ -53,6 +57,7 @@ const getInitialValues = (tutorial: FormikValues | null) => {
howToDo: "",
referenceImage: "",
referenceVideo: "",
taskItemMark: 0,
}
]
}
......@@ -67,37 +72,36 @@ const getInitialValues = (tutorial: FormikValues | null) => {
// ==============================|| CUSTOMER ADD / EDIT ||============================== //
export interface Props {
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[]
};
tutorial?: Tutorial
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 theme = useTheme();
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);
......@@ -115,7 +119,13 @@ const AddEditTutorial = ({ tutorial, onCancel }: Props) => {
if (tutorial) {
// PUT API
} else {
// POST API
// POST API
//@ts-ignore
// const req: Tutorial = { ...values }
const sampleReq: Tutorial = tutorialReqOb
//@ts-ignore
dispatch(addTutorial(sampleReq))
}
resetForm()
setSubmitting(false);
......@@ -266,7 +276,7 @@ const AddEditTutorial = ({ tutorial, onCancel }: Props) => {
</AccordionSummary>
<AccordionDetails>
<Grid container spacing={2}>
<Grid item xs={12}>
<Grid item xs={6}>
<Stack spacing={1.25}>
<InputLabel htmlFor={`taskItems.${index}.title`}>Task Title</InputLabel>
<TextField
......@@ -274,8 +284,37 @@ const AddEditTutorial = ({ tutorial, onCancel }: Props) => {
id={`taskItems.${index}.title`}
placeholder="Enter Task Title"
{...getFieldProps(`taskItems.${index}.title`)}
// error={Boolean(touched.ingredientNutritions![index].nutritionCategory && errors.ingredientNutritions![index].nutritionCategory)}
// helperText={touched.ingredientNutritions![index].nutritionCategory && errors.ingredientNutritions![index].nutritionCategory}
error={Boolean(
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>
</Grid>
......@@ -287,8 +326,16 @@ const AddEditTutorial = ({ tutorial, onCancel }: Props) => {
id={`taskItems.${index}.referenceImage`}
placeholder="Enter Task Reference Image"
{...getFieldProps(`taskItems.${index}.referenceImage`)}
// error={Boolean(touched.ingredientNutritions![index].nutritionCategory && errors.ingredientNutritions![index].nutritionCategory)}
// helperText={touched.ingredientNutritions![index].nutritionCategory && errors.ingredientNutritions![index].nutritionCategory}
error={Boolean(
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>
</Grid>
......@@ -300,8 +347,16 @@ const AddEditTutorial = ({ tutorial, onCancel }: Props) => {
id={`taskItems.${index}.referenceVideo`}
placeholder="Enter Task Reference Video"
{...getFieldProps(`taskItems.${index}.referenceVideo`)}
// error={Boolean(touched.ingredientNutritions![index].nutritionCategory && errors.ingredientNutritions![index].nutritionCategory)}
// helperText={touched.ingredientNutritions![index].nutritionCategory && errors.ingredientNutritions![index].nutritionCategory}
error={Boolean(
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>
</Grid>
......@@ -313,8 +368,16 @@ const AddEditTutorial = ({ tutorial, onCancel }: Props) => {
id={`taskItems.${index}.description`}
placeholder="Enter Task Description"
{...getFieldProps(`taskItems.${index}.description`)}
// error={Boolean(touched.ingredientNutritions![index].nutritionCategory && errors.ingredientNutritions![index].nutritionCategory)}
// helperText={touched.ingredientNutritions![index].nutritionCategory && errors.ingredientNutritions![index].nutritionCategory}
error={Boolean(
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>
</Grid>
......@@ -326,8 +389,16 @@ const AddEditTutorial = ({ tutorial, onCancel }: Props) => {
id={`taskItems.${index}.howToDo`}
placeholder="Enter Task How To Do"
{...getFieldProps(`taskItems.${index}.howToDo`)}
// error={Boolean(touched.ingredientNutritions![index].nutritionCategory && errors.ingredientNutritions![index].nutritionCategory)}
// helperText={touched.ingredientNutritions![index].nutritionCategory && errors.ingredientNutritions![index].nutritionCategory}
error={Boolean(
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>
</Grid>
......
......@@ -21,11 +21,11 @@ export type Tutorial = {
tutorialTitle?: string
tutorialDescription?: string
tutorialImage?: string
tutorialMark: number
tutorialMark?: number
taskItems: taskItemType[]
status: number
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