Skip to content

Commit 1428f11

Browse files
destin-estrelaDestin Estrela
andauthored
Marketplace: Create,View, Edit, and Delete Listings (#53)
* Shoe market listings by course selected (unstyled) * Various styling to market listing * Styling improvements to market listings * Create Listing Dialog button and form functionality * Update listings with optimistic UI when adding * Add image in temp object * Added loading circle * Removed picture * Show listing details when clicked * Added delete button to market listing * Centered listing loading bar * Edit listing dialog * Fixed lint errors Co-authored-by: Destin Estrela <[email protected]>
1 parent a81b2de commit 1428f11

File tree

11 files changed

+1989
-72
lines changed

11 files changed

+1989
-72
lines changed

graphql.schema.json

Lines changed: 1062 additions & 40 deletions
Large diffs are not rendered by default.

src/App/App.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { withAuthenticator } from 'aws-amplify-react';
55
import Sidebar from '../Components/Sidebar';
66
import Content from '../Components/Content';
77
import Navigation from '../Navigation/Navigation';
8-
import StudentPicture from '../assets/images/images-1.png';
98

109
import './App.scss';
1110

@@ -58,9 +57,6 @@ function App() {
5857
<div className="main container-fluid">
5958
<div className="row h-100">
6059
<div className="sidebar-container col-md-2 p-0 side">
61-
<div className="img-container">
62-
<img src={StudentPicture} alt="" className="img-fluid" />
63-
</div>
6460
<div className="pl-2 pt-2 pr-2">{fname}</div>
6561
<Sidebar />
6662
</div>

src/Components/Content/Content.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ import TaskSubmissionOverview from '../TaskSubmissionOverview';
66
import ViewTaskSubmission from '../ViewTaskSubmission';
77
import SingleStudentOverview from '../SingleStudentOverview/SingleStudentOverview';
88
import SingleStudentMasteryOverview from '../SingleStudentMasteryOverview/SingleStudentMasteryOverview';
9-
import CourseHome from '../CourseHome/CourseHome';
109
import SingleTargetOverview from '../SingleTargetOverview/SingleTargetOverview';
1110
import SingleMissionOverview from '../SingleStudentOverview/SingleMissionOverview';
1211
import TaskView from '../../Screens/TaskView/TaskView';
1312
import TaskListView from '../TaskListView';
1413
import TaskSubmissionSummaryView from '../TaskSubmissionSummaryView';
1514
import { ClassMastery } from '../../Screens/ClassMastery';
1615
import './Content.css';
16+
import MarketHome from '../MarketHome/MarketHome';
1717

1818
export default function Content() {
1919
return (
2020
<div className="content">
2121
<Switch>
2222
<Route path="/courseHome/:className">
23-
<CourseHome />
23+
<MarketHome />
2424
</Route>
2525
<Route path="/addNewCourse">
2626
<CreateCourseDialog />
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/* eslint-disable @typescript-eslint/no-unsafe-return */
2+
import { Button, Dialog, DialogTitle, DialogContent } from '@material-ui/core';
3+
import { useState } from 'react';
4+
import styled from 'styled-components';
5+
import { MarketListingInput, useAddListingMutation } from '../../__generated__/types';
6+
import ListingForm, { MarketListingFormInput } from './ListingForm';
7+
8+
const Container = styled.div`
9+
text-align: left;
10+
fontfamily: 'Poppins', sans-serif;
11+
margin-left: 36px;
12+
`;
13+
14+
type Props = {
15+
course: string;
16+
callback: any;
17+
refetch: any;
18+
};
19+
20+
export function listingFormToInputType(values: MarketListingFormInput): MarketListingInput {
21+
return {
22+
listingName: values.listingName,
23+
description: values.description,
24+
image: values.image,
25+
price: parseInt(values.price, 10),
26+
stock: values.stock === '' ? -1 : parseInt(values.stock, 10),
27+
};
28+
}
29+
30+
function CreateListingDialog(props: Props) {
31+
const [open, setOpen] = useState(false);
32+
const [addListing] = useAddListingMutation();
33+
34+
const initialValues: MarketListingFormInput = {
35+
price: '',
36+
stock: '',
37+
image: 'https://d29fhpw069ctt2.cloudfront.net/icon/image/73614/preview.svg',
38+
description: '',
39+
listingName: '',
40+
};
41+
42+
const handleClickOpen = () => {
43+
setOpen(true);
44+
};
45+
46+
const handleClose = () => {
47+
setOpen(false);
48+
};
49+
50+
const handleSubmit = (values: MarketListingFormInput) => {
51+
props.callback({
52+
listingName: values.listingName,
53+
price: values.price,
54+
image: values.image,
55+
});
56+
handleClose();
57+
addListing({
58+
variables: {
59+
course: props.course,
60+
input: listingFormToInputType(values),
61+
},
62+
optimisticResponse: {
63+
__typename: 'Mutation',
64+
addMarketListing: {
65+
course: props.course,
66+
timesPurchased: 0,
67+
__typename: 'MarketListing',
68+
id: 'temp',
69+
listedDate: new Date(),
70+
listingName: values.listingName,
71+
description: values.description,
72+
image: values.image,
73+
price: parseInt(values.price, 10),
74+
stock: values.stock === '' ? -1 : parseInt(values.stock, 10),
75+
},
76+
},
77+
})
78+
.then(() => props.refetch())
79+
.catch((error) => console.log(error));
80+
};
81+
82+
return (
83+
<Container>
84+
<div>
85+
<Button
86+
style={{
87+
width: 200,
88+
marginTop: 20,
89+
backgroundColor: '#4274F3',
90+
color: 'white',
91+
}}
92+
onClick={handleClickOpen}
93+
data-testid="create-btn"
94+
>
95+
Create New Listing
96+
</Button>
97+
<Dialog
98+
open={open}
99+
fullWidth
100+
onClose={handleClose}
101+
aria-labelledby="form-dialog-title"
102+
maxWidth="sm"
103+
data-testid="create-dialog"
104+
>
105+
<DialogTitle
106+
style={{ backgroundColor: '#4274F3', color: 'white' }}
107+
id="form-dialog-title"
108+
>
109+
New Listing
110+
</DialogTitle>
111+
<DialogContent>
112+
<ListingForm
113+
initialValues={initialValues}
114+
handleClose={handleClose}
115+
onSubmit={handleSubmit}
116+
/>
117+
</DialogContent>
118+
</Dialog>
119+
</div>
120+
</Container>
121+
);
122+
}
123+
124+
export default CreateListingDialog;
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
.market-course-header {
2+
margin-left: 36px;
3+
}
4+
5+
.center {
6+
margin: auto;
7+
margin-top: 5em;
8+
width: 50%;
9+
}
10+
11+
.listing-card-outer {
12+
display: inline-block;
13+
}
14+
15+
.listing-card {
16+
border: 1px solid rgb(255, 255, 255);
17+
margin: 12px;
18+
box-sizing: border-box;
19+
box-shadow: 0 6px 10px rgba(0, 0, 0, 0.3);
20+
border-radius: 8px;
21+
overflow: hidden;
22+
background: #fff;
23+
width: 300px;
24+
height: 150px;
25+
display: inline-block;
26+
vertical-align: top;
27+
position: relative;
28+
}
29+
30+
.listing-card-details {
31+
margin-top: 1em;
32+
}
33+
34+
.listing-card {
35+
.listing-card-image {
36+
padding-left: 15px;
37+
float: left;
38+
margin: 0px auto;
39+
position: absolute;
40+
top: 50%;
41+
-ms-transform: translateY(-50%);
42+
transform: translateY(-50%);
43+
width: 40;
44+
height: 40;
45+
border-radius: 50%;
46+
}
47+
48+
.listing-card-header {
49+
display: block;
50+
height: 0px;
51+
}
52+
53+
.listing-card-body {
54+
float: right;
55+
width: 55%;
56+
padding-top: 10%;
57+
padding-right: 9%;
58+
.listing-title {
59+
font-size: 1.4em;
60+
color: black;
61+
display: inline-flex;
62+
align-content: center;
63+
}
64+
.listing-points {
65+
color: rgb(0, 0, 0);
66+
font-size: 1.5em;
67+
font-weight: bold;
68+
}
69+
}
70+
}
71+
72+
.listing-icon {
73+
margin-left: 10px;
74+
margin-bottom: 10px;
75+
}

0 commit comments

Comments
 (0)