diff --git a/frontend/src/components/item-card/item-card.jsx b/frontend/src/components/item-card/item-card.jsx index 6f8757b..da082af 100644 --- a/frontend/src/components/item-card/item-card.jsx +++ b/frontend/src/components/item-card/item-card.jsx @@ -1,195 +1,201 @@ -import React, { useState } from 'react'; -import { CreditCard, Person, SignalCellularAlt } from '@mui/icons-material'; -import { Button, Card, CardActions, CardContent, CardHeader, Chip, Divider, Stack, Typography } from '@mui/material'; +import React, {useState} from 'react'; +import {CreditCard, Person, SignalCellularAlt} from '@mui/icons-material'; +import {Button, Card, CardActions, CardContent, CardHeader, Chip, Divider, Stack, Typography} from '@mui/material'; import PropTypes from 'prop-types'; import MoreInfoModal from './more-info-modal'; +import {Helper} from "../../utils/Helper.js"; -export const Presenter = ({ presenterName }) => ( - - - - {presenterName} - - +export const Presenter = ({presenterName}) => ( + + + + {presenterName} + + ); -export const Cost = ({ cost }) => ( - - - - {cost} T - - +export const Cost = ({cost}) => ( + + + + {cost} T + + ); -const CapacityChip = ({ capacity, isFull }) => ( - +const CapacityChip = ({capacity, isFull, remainingCapacity}) => ( + ); -const Level = ({ name, color }) => ( - - - - {name} - - +const Level = ({name, color}) => ( + + + + {name} + + ); export const levelComponentMapping = { - Elementary: , - Intermediate: , - Advanced: , + Elementary: , + Intermediate: , + Advanced: , }; const ItemCard = ({ - title = 'Title', - isWorkshop = true, - description = 'Default Description', - startDate = '2021-08-27 06:00', - endDate = '2021-08-31 18:00', - presenterName = 'Presenter Name', - level = 'elementary', - cost = 50000, - purchaseState = 0, // 0 -> not purchased, 1 -> in cart, 2 -> purchased - hasProject = true, - prerequisites = 'List of prerequisites', - syllabus = 'List of syllabus', - capacity = 50, - isFull = false, - addToCalendarLink = 'https://google.com', - onClickAddToCart = () => {}, - onClickRemoveFromCart = () => {}, -}) => { - const [moreInfoModalVisibility, setMoreInfoModalVisibility] = useState(false); - const hasBought = purchaseState === 2; + title = 'Title', + isWorkshop = true, + description = 'Default Description', + startDate = '2021-08-27 06:00', + endDate = '2021-08-31 18:00', + presenterName = 'Presenter Name', + level = 'elementary', + cost = 50000, + purchaseState = 0, // 0 -> not purchased, 1 -> in cart, 2 -> purchased + hasProject = true, + prerequisites = 'List of prerequisites', + syllabus = 'List of syllabus', + remainingCapacity = 50, + capacity = 50, + isFull = false, + addToCalendarLink = 'https://google.com', + onClickAddToCart = () => { + }, + onClickRemoveFromCart = () => { + }, + }) => { + const [moreInfoModalVisibility, setMoreInfoModalVisibility] = useState(false); + const hasBought = purchaseState === 2; - const handleClickOnMoreInfo = () => { - setMoreInfoModalVisibility(true); - }; + const handleClickOnMoreInfo = () => { + setMoreInfoModalVisibility(true); + }; - const getActionComponent = () => { - switch (purchaseState) { - case 0: - return ( - - ); - case 1: - return ( - - ); - case 2: - return ( - - ); - default: - return null; - } - }; + const getActionComponent = () => { + switch (purchaseState) { + case 0: + return ( + + ); + case 1: + return ( + + ); + case 2: + return ( + + ); + default: + return null; + } + }; - return ( - <> - setMoreInfoModalVisibility(false)} - title={title} - presenterName={presenterName} - cost={cost} - purchaseState={purchaseState} - level={level} - hasProject={hasProject} - prerequisites={prerequisites} - syllabus={syllabus} - isFull={isFull} - addToCalendarLink={addToCalendarLink} - onClickAddToCart={onClickAddToCart} - onClickRemoveFromCart={onClickRemoveFromCart} - /> - - - - - {description} - - - From: {new Date(startDate).toLocaleString('fa-IR-u-nu-latn')} - - - To: {new Date(endDate).toLocaleString('fa-IR-u-nu-latn')} - - - - {levelComponentMapping[level]} - {!hasBought && } - {!hasBought && } - - - - {getActionComponent()} - - - - ); + return ( + <> + setMoreInfoModalVisibility(false)} + title={title} + presenterName={presenterName} + cost={cost} + purchaseState={purchaseState} + description={description} + level={level} + hasProject={hasProject} + prerequisites={prerequisites} + syllabus={syllabus} + isFull={isFull} + addToCalendarLink={addToCalendarLink} + onClickAddToCart={onClickAddToCart} + onClickRemoveFromCart={onClickRemoveFromCart} + /> + + + + + {Helper.omitLongString(description, 50)} + + + From: {new Date(startDate).toLocaleString('fa-IR-u-nu-latn')} + + + To: {new Date(endDate).toLocaleString('fa-IR-u-nu-latn')} + + + + {levelComponentMapping[level]} + {!hasBought && } + {!hasBought && } + + + + {getActionComponent()} + + + + ); }; ItemCard.propTypes = { - title: PropTypes.string, - isWorkshop: PropTypes.bool, - description: PropTypes.string, - startDate: PropTypes.string, - endDate: PropTypes.string, - presenterName: PropTypes.string, - level: PropTypes.string, - cost: PropTypes.number, - purchaseState: PropTypes.number, - hasProject: PropTypes.bool, - prerequisites: PropTypes.string, - syllabus: PropTypes.string, - capacity: PropTypes.number, - isFull: PropTypes.bool, - addToCalendarLink: PropTypes.string, - onClickAddToCart: PropTypes.func, + title: PropTypes.string, + isWorkshop: PropTypes.bool, + description: PropTypes.string, + startDate: PropTypes.string, + endDate: PropTypes.string, + presenterName: PropTypes.string, + level: PropTypes.string, + cost: PropTypes.number, + purchaseState: PropTypes.number, + hasProject: PropTypes.bool, + prerequisites: PropTypes.string, + syllabus: PropTypes.string, + capacity: PropTypes.number, + isFull: PropTypes.bool, + addToCalendarLink: PropTypes.string, + onClickAddToCart: PropTypes.func, + remainingCapacity: PropTypes.number }; export default ItemCard; diff --git a/frontend/src/components/item-card/more-info-modal.jsx b/frontend/src/components/item-card/more-info-modal.jsx index ef7c147..c9daac4 100644 --- a/frontend/src/components/item-card/more-info-modal.jsx +++ b/frontend/src/components/item-card/more-info-modal.jsx @@ -1,6 +1,7 @@ import React from 'react'; import { Checklist } from '@mui/icons-material'; import ListIcon from '@mui/icons-material/List'; +import InfoIcon from '@mui/icons-material/Info'; import { Dialog, DialogTitle, @@ -10,7 +11,7 @@ import { Button, Divider, Stack, - Chip, + Chip, Icon, Box, } from '@mui/material'; import PropTypes from 'prop-types'; import { Cost, levelComponentMapping, Presenter } from './item-card'; @@ -46,6 +47,7 @@ const MoreInfoModal = ({ presenterName, cost, level, + description, purchaseState, hasProject, prerequisites, @@ -71,6 +73,14 @@ const MoreInfoModal = ({ > {title} +
+ + {description && {description}} +
{levelComponentMapping[level]} @@ -111,6 +121,7 @@ MoreInfoModal.propTypes = { prerequisites: PropTypes.string, syllabus: PropTypes.string, isFull: PropTypes.bool, + description: PropTypes.string, onClickAddToCart: PropTypes.func, onClickRemoveFromCart: PropTypes.func, };