Skip to content

Commit

Permalink
fix(Checkout.tsx): removed checkout page from router, styling
Browse files Browse the repository at this point in the history
  • Loading branch information
capture120 committed Dec 5, 2023
2 parents 94f3aae + c6ea51d commit c8a3d17
Show file tree
Hide file tree
Showing 12 changed files with 502 additions and 102 deletions.
2 changes: 1 addition & 1 deletion backend/schema/job/job-model.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func GetJobById(jobId string, dbClient *mongo.Client) (schema.Job, *schema.Error
}

// Find a specified job by either a producer or designer ID
func GetJobsByDesignerOrProducerId(designerId primitive.ObjectID, producerId primitive.ObjectID, status string, limit int64, skip int64, dbClient *mongo.Client) ([]schema.Job, *schema.ErrorResponse) {
func GetJobsByDesignerOrProducerId(designerId primitive.ObjectID, producerId primitive.ObjectID, status string, limit int64, skip int64, dbClient *mongo.Client) ([]schema.JobView, *schema.ErrorResponse) {
return getJobsByDesignerOrProducerIdDb(designerId, producerId, status, limit, skip, dbClient)
}

Expand Down
16 changes: 12 additions & 4 deletions backend/schema/job/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ func TestGetJobsByDesignerOrProducerId(t *testing.T) {
producerId, _ := primitive.ObjectIDFromHex("")
// string version of ObjectID used for comparisons
jobIdHex := designerId
expectedJob := schema.Job{
expectedJob := schema.JobView{
Id: jobId,
DesignerId: designerId,
Status: schema.Pending,
Expand All @@ -885,6 +885,10 @@ func TestGetJobsByDesignerOrProducerId(t *testing.T) {
Coordinates: orb.Point{1, 1},
},
},
DesignerFirstName: "Kevin",
DesignerLastName: "Durant",
ProducerFirstName: "Lebron",
ProducerLastName: "James",
}
jobBSON, _ := bson.Marshal(expectedJob)
var jobBsonData bson.D
Expand All @@ -909,7 +913,7 @@ func TestGetJobsByDesignerOrProducerId(t *testing.T) {
foundJob, err := GetJobsByDesignerOrProducerId(jobIdHex, producerId, "", 10, 0, mt.Client)

assert.Nil(err)
assert.Equal(foundJob, []schema.Job{expectedJob})
assert.Equal(foundJob, []schema.JobView{expectedJob})
})

mt.Run("Get Producer Jobs by ID", func(mt *mtest.T) {
Expand All @@ -919,7 +923,7 @@ func TestGetJobsByDesignerOrProducerId(t *testing.T) {
producerId := primitive.NewObjectID()
// string version of ObjectID used for comparisons
jobIdHex := producerId
expectedJob := schema.Job{
expectedJob := schema.JobView{
Id: jobId,
ProducerId: producerId,
Status: schema.Pending,
Expand All @@ -938,6 +942,10 @@ func TestGetJobsByDesignerOrProducerId(t *testing.T) {
Coordinates: orb.Point{1, 1},
},
},
DesignerFirstName: "Kevin",
DesignerLastName: "Durant",
ProducerFirstName: "Lebron",
ProducerLastName: "James",
}
jobBSON, _ := bson.Marshal(expectedJob)
var jobBsonData bson.D
Expand All @@ -962,7 +970,7 @@ func TestGetJobsByDesignerOrProducerId(t *testing.T) {
foundJob, err := GetJobsByDesignerOrProducerId(designerId, jobIdHex, "", 10, 0, mt.Client)

assert.Nil(err)
assert.Equal(foundJob, []schema.Job{expectedJob})
assert.Equal(foundJob, []schema.JobView{expectedJob})
})

mt.Run("Retrieving Non-existing ID throws error", func(mt *mtest.T) {
Expand Down
58 changes: 45 additions & 13 deletions backend/schema/job/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
// "go.mongodb.org/mongo-driver/mongo/options"
)

// Find a specified job by its ID
Expand All @@ -34,7 +35,7 @@ func getJobByIdDb(jobId string, dbClient *mongo.Client) (schema.Job, *schema.Err
}

// Find a specified job by either a producer or designer ID
func getJobsByDesignerOrProducerIdDb(designerId primitive.ObjectID, producerId primitive.ObjectID, status string, limit int64, skip int64, dbClient *mongo.Client) ([]schema.Job, *schema.ErrorResponse) {
func getJobsByDesignerOrProducerIdDb(designerId primitive.ObjectID, producerId primitive.ObjectID, status string, limit int64, skip int64, dbClient *mongo.Client) ([]schema.JobView, *schema.ErrorResponse) {
// load jobs collection
jobCollection := dbClient.Database(schema.DatabaseName).Collection("jobs")

Expand All @@ -49,36 +50,67 @@ func getJobsByDesignerOrProducerIdDb(designerId primitive.ObjectID, producerId p
filter = append(filter, bson.E{Key: "status", Value: status})
}

var jobs []schema.Job

// pagination options
paginationOptions := options.Find()
paginationOptions.SetLimit(limit)
paginationOptions.SetSkip(skip)
pipeline := mongo.Pipeline{
bson.D{{Key: "$match", Value: filter}},
// Left outer join on producer ID
bson.D{{Key: "$lookup", Value: bson.D{
{Key: "from", Value: "users"},
{Key: "localField", Value: "producerId"},
{Key: "foreignField", Value: "_id"},
{Key: "as", Value: "producer"},
}}},
bson.D{{Key: "$unwind", Value: bson.D{
{Key: "path", Value: "$producer"},
{Key: "preserveNullAndEmptyArrays", Value: true},
}}},
bson.D{{Key: "$addFields", Value: bson.D{
{Key: "producerFirstName", Value: "$producer.firstName"},
{Key: "producerLastName", Value: "$producer.lastName"},
}}},
// Left outer join on designer ID
bson.D{{Key: "$lookup", Value: bson.D{
{Key: "from", Value: "users"},
{Key: "localField", Value: "designerId"},
{Key: "foreignField", Value: "_id"},
{Key: "as", Value: "designer"},
}}},
bson.D{{Key: "$unwind", Value: bson.D{
{Key: "path", Value: "$designer"},
{Key: "preserveNullAndEmptyArrays", Value: true},
}}},
bson.D{{Key: "$addFields", Value: bson.D{
{Key: "designerFirstName", Value: "$designer.firstName"},
{Key: "designerLastName", Value: "$designer.lastName"},
}}},
bson.D{{Key: "$skip", Value: skip}},
bson.D{{Key: "$limit", Value: limit}},
}

// If jobs are not found, throw an error
cursor, err := jobCollection.Find(context.Background(), filter, paginationOptions)
cursor, err := jobCollection.Aggregate(context.Background(), pipeline)
if err != nil {
return []schema.Job{}, &schema.ErrorResponse{Code: 404, Message: "Job does not exist!"}
return []schema.JobView{}, &schema.ErrorResponse{Code: 404, Message: "Job does not exist!"}
}
defer cursor.Close(context.Background())

var jobs []schema.JobView

// Iterate over the cursor and append each job to the slice
for cursor.Next(context.Background()) {
var job schema.Job
var job schema.JobView
if err := cursor.Decode(&job); err != nil {
return []schema.Job{}, &schema.ErrorResponse{Code: 500, Message: "Error decoding job!"}
return []schema.JobView{}, &schema.ErrorResponse{Code: 500, Message: "Error decoding job!"}
}
jobs = append(jobs, job)
}

// If there was an error iterating over the cursor, return an error
if err := cursor.Err(); err != nil {
return []schema.Job{}, &schema.ErrorResponse{Code: 500, Message: "Error iterating over jobs!"}
return []schema.JobView{}, &schema.ErrorResponse{Code: 500, Message: "Error iterating over jobs!"}
}
// If no jobs exist (ex: there are 2 pages but user tries to go to "page 3")
if jobs == nil {
return []schema.Job{}, &schema.ErrorResponse{Code: 400, Message: "Page does not exist"}
return []schema.JobView{}, &schema.ErrorResponse{Code: 400, Message: "Page does not exist"}
}

// Return the jobs
Expand Down
21 changes: 21 additions & 0 deletions backend/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,27 @@ type Job struct {
// lastUpdated represents last time a potential producer was added
}

type JobView struct {
Id primitive.ObjectID `bson:"_id,omitempty" json:"id"`
CreatedAt primitive.DateTime `bson:"createdAt,omitempty" json:"createdAt"`
DesignerId primitive.ObjectID `bson:"designerId,omitempty" json:"designerId"`
ProducerId primitive.ObjectID `bson:"producerId,omitempty" json:"producerId"`
DesignId []primitive.ObjectID `bson:"designId,omitempty" json:"designId"`
Quantity []int32 `bson:"quantity,omitempty" json:"quantity"`
Status JobStatus `bson:"status,omitempty" json:"status"`
Price int `bson:"price,omitempty" json:"price"`
Shipping int `bson:"shipping,omitempty" json:"shipping"`
Taxes int `bson:"taxes,omitempty" json:"taxes"`
Color string `bson:"color,omitempty" json:"color"`
Filament FilamentType `bson:"filament,omitempty" json:"filament"`
LayerHeight float64 `bson:"layerHeight,omitempty" json:"layerHeight"`
ShippingAddress Address `bson:"shippingAddress,omitempty" json:"shippingAddress"`
ProducerFirstName string `bson:"producerFirstName,omitempty" json:"producerFirstName"`
ProducerLastName string `bson:"producerLastName,omitempty" json:"producerLastName"`
DesignerFirstName string `bson:"designerFirstName,omitempty" json:"designerFirstName"`
DesignerLastName string `bson:"designerLastName,omitempty" json:"designerLastName"`
}

// A Design is just a GridFS file, but renamed to match Voxeti branding
type Design struct {
Id primitive.ObjectID `bson:"_id" json:"id"`
Expand Down
1 change: 0 additions & 1 deletion frontend/src/api/tempCodeRunnerFile.ts

This file was deleted.

2 changes: 1 addition & 1 deletion frontend/src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function StyledButton({
seconday: ["!bg-[#F5F5F5]", "!text-primary", "hover:!bg-[#D3D3D3]"],
producer: ["!bg-producer", "!text-background", "hover:!bg-[#565656]"],
designer: ["!bg-designer", "!text-background", "hover:!bg-[#565656]"],
delete: ["!bg-[#F5F5F5]", "!text-primary", "hover:!bg-[#FFCCCB]"],
delete: ["!bg-[#F5F5F5]", "!text-error", "hover:!bg-[#FFCCCB]"],
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,44 @@ import { userApi } from "../../../../api/api";
import { Job } from "../../../../main.types";
import { Avatar } from "@mui/material";
import JobAcceptButtons from "./JobAcceptButtons";
import { Skeleton } from "@mui/material";

export default function DesignerName(props: { job: Job }) {
const { data: data } = userApi.useGetUserQuery(props.job.designerId);
function capitalize(str?: string) {
return str ? str[0].toUpperCase() + str.slice(1).toLowerCase() : "";
}

export default function DesignerName(props: { designerId: string; job?: Job }) {
const { data: data } = userApi.useGetUserQuery(props.designerId);
return (
<div className=" flex flex-col w-full">
<div className=" flex flex-row items-center justify-between w-full">
<div className=" flex flex-row">
<Avatar
className=" outline outline-3 outline-offset-2 outline-designer"
alt={data ? `${data.firstName} ${data.lastName}` : ""}
src="/static/images/avatar/1.jpg"
sx={{ width: 64, height: 64 }}
/>
<div className=" px-4">
<p className=" text-lg">
{data && data.firstName} {data && data.lastName}
</p>
<p className=" text-sm">Designer</p>
</div>
{data ? (
<Avatar
className={` outline outline-3 outline-offset-2 ${
data.userType == "DESIGNER"
? "outline-designer"
: "outline-producer"
}`}
alt={`${data.firstName} ${data.lastName}`}
sx={{ width: 64, height: 64 }}
/>
) : (
<Skeleton variant="circular" width={64} height={64} />
)}
{data ? (
<div className=" px-4 flex flex-col justify-center">
<p className=" text-lg">
{data && data.firstName} {data && data.lastName}
</p>
<p className=" text-sm opacity-70">{capitalize(data.userType)}</p>
</div>
) : (
<div className=" px-4 flex flex-col justify-center">
<Skeleton variant="rectangular" width={96} height={28} />
<Skeleton variant="rectangular" width={48} height={20} />
</div>
)}
</div>
{props.job && <JobAcceptButtons currentJob={props.job} />}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,8 @@ export default function Checkout({states, setters}: CheckoutProps) {
const [clientSecret, setClientSecret] = useState('');
const [createCheckoutSession] = paymentApi.useCreatePaymentMutation();
const hasBeenEvaluated = useRef(false);
// const base = "http://localhost:3000/api/"

useEffect(() => {
// Create a Checkout Session as soon as the page loads
// console.log("Doing the embedded stripe work")
// fetch(base + "payment/create-checkout-session", {
// method: "POST",
// body: JSON.stringify({ prices: states.prices, quantities: states.quantities }),
// })
// .then((res) => res.json())
// .then((data) => setClientSecret(data.client_secret));
async function makeCheckoutSession() {
if (!states.prices || !states.quantities || clientSecret !== '') {
return;
Expand Down
50 changes: 0 additions & 50 deletions frontend/src/pages/CheckoutPage.tsx

This file was deleted.

7 changes: 6 additions & 1 deletion frontend/src/pages/JobInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@ export default function JobInfo() {
<BackButton />
<div className=" py-3" />
<div className=" flex flex-row justify-between">
{currentJob && <DesignerName job={currentJob} />}
{currentJob && (
<DesignerName
designerId={currentJob.designerId}
job={currentJob}
/>
)}
</div>
{currentJob &&
currentJob.designId.map(
Expand Down
Loading

0 comments on commit c8a3d17

Please sign in to comment.