Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
7bb68e7
feat: purchase details page fully styled (not dynamic yet tho), added…
aaronkim218 Dec 6, 2023
1603692
Merge branch 'main' of https://github.com/GenerateNU/voxeti into job-…
aaronkim218 Dec 6, 2023
fbe17ce
feat: purchase details page fully functional, changed address locatio…
aaronkim218 Dec 6, 2023
219d45c
refactor: add tracking number to backend and make tracking number opt…
aaronkim218 Dec 7, 2023
921fb20
refactor: style changes
aaronkim218 Dec 7, 2023
c244a5a
feat: add estimatedDelivery to job schema frontend and backend
aaronkim218 Dec 7, 2023
6254274
feat: add purchase history page
aaronkim218 Dec 7, 2023
f01c86d
refactor: only display purchase history if user is designer
aaronkim218 Dec 7, 2023
edf2b54
Merge branch 'main' of https://github.com/GenerateNU/voxeti into job-…
aaronkim218 Dec 7, 2023
099a1cf
Merge branch 'main' of https://github.com/GenerateNU/voxeti into job-…
aaronkim218 Dec 8, 2023
3d2eb84
refactor: fix custom avatar component, fix purchase history page, fix…
aaronkim218 Dec 8, 2023
4c03332
refactor: linter changes
aaronkim218 Dec 8, 2023
307d4d0
refactor: remove old unused components, and change all avatars to Sty…
aaronkim218 Dec 8, 2023
6ade871
refactor: fix StyledAvatar
aaronkim218 Dec 8, 2023
a839f45
refactor: calculate price correctly
aaronkim218 Dec 8, 2023
2c25b2a
feat: add date ascending sort, so most recent purchases will display …
aaronkim218 Dec 8, 2023
1d47fa5
refactor: i meant descending lmao
aaronkim218 Dec 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion backend/controller/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func RegisterJobHandlers(e *echo.Group, dbClient *mongo.Client, logger *pterm.Lo
designerId := c.QueryParam("designer")
producerId := c.QueryParam("producer")
status := c.QueryParam("status")
sort := c.QueryParam("sort")
page_num, _ := strconv.Atoi(c.QueryParam("page")) // the current page the user is on
skip := limit * page_num

Expand All @@ -45,7 +46,7 @@ func RegisterJobHandlers(e *echo.Group, dbClient *mongo.Client, logger *pterm.Lo
if page_num < 0 {
return c.JSON(utilities.CreateErrorResponse(400, "Invalid page number"))
}
retrievedJobs, errorResponse := job.GetJobsByDesignerOrProducerId(designerIdObj, producerIdObj, status, int64(limit), int64(skip), dbClient)
retrievedJobs, errorResponse := job.GetJobsByDesignerOrProducerId(designerIdObj, producerIdObj, status, sort, int64(limit), int64(skip), dbClient)
if errorResponse != nil {
return c.JSON(utilities.CreateErrorResponse(errorResponse.Code, errorResponse.Message))
}
Expand Down
40 changes: 36 additions & 4 deletions backend/schema/job/job-model.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,23 @@ 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.JobView, *schema.ErrorResponse) {
return getJobsByDesignerOrProducerIdDb(designerId, producerId, status, limit, skip, dbClient)
func GetJobsByDesignerOrProducerId(designerId primitive.ObjectID, producerId primitive.ObjectID, status string, sort string, limit int64, skip int64, dbClient *mongo.Client) ([]schema.JobView, *schema.ErrorResponse) {
jobs, err := getJobsByDesignerOrProducerIdDb(designerId, producerId, status, limit, skip, dbClient)
if err != nil {
return nil, err
}

if sort != "" {
sorter, err := getRecommendationSorter(sort)
if err != nil {
return nil, err
}

sortedJobs := sortJobViews(&jobs, sorter)
return *sortedJobs, nil
}

return jobs, nil
}

// Delete a job
Expand Down Expand Up @@ -308,7 +323,8 @@ func filterJobs(producer *schema.User, filters []RecommendationFilter, dbClient
type RecommendationSorter string

const (
Price = "PRICE"
Price = "PRICE"
DateDESC = "DATEDESC"
)

func sortJobs(jobs *[]schema.Job, sorter RecommendationSorter) *[]schema.Job {
Expand All @@ -324,6 +340,20 @@ func sortJobs(jobs *[]schema.Job, sorter RecommendationSorter) *[]schema.Job {
}
}

func sortJobViews(jobViews *[]schema.JobView, sorter RecommendationSorter) *[]schema.JobView {
switch sorter {
case DateDESC:
s := func(jobView1 schema.JobView, jobView2 schema.JobView) int {
duration := jobView2.CreatedAt.Time().Sub(jobView1.CreatedAt.Time())
return int(duration.Seconds())
}
slices.SortFunc(*jobViews, s)
return jobViews
default:
return jobViews
}
}

// extract filters from query param
func getRecommendationFilters(filter string) ([]RecommendationFilter, *schema.ErrorResponse) {
var filters []RecommendationFilter
Expand Down Expand Up @@ -352,6 +382,8 @@ func getRecommendationSorter(sort string) (RecommendationSorter, *schema.ErrorRe
switch sort {
case "PRICE":
return Price, nil
case "DATEDESC":
return DateDESC, nil
default:
return "", &schema.ErrorResponse{Code: 400, Message: "Invalid sort"}
}
Expand All @@ -374,7 +406,7 @@ func updatePotentialProducers(producerId *primitive.ObjectID, jobs *[]schema.Job

func TransferPotentialToDeclined(dbClient *mongo.Client, logger *pterm.Logger) {
for {
const TIME_INTERVAL = 12 * time.Minute
const TIME_INTERVAL = 12 * time.Hour
const MAX_INACTIVE = 12 * time.Hour
const TRANSFER_NUM = 5

Expand Down
4 changes: 2 additions & 2 deletions backend/schema/job/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ func TestGetJobsByDesignerOrProducerId(t *testing.T) {
mt.AddMockResponses(res, end)

// Assertions
foundJob, err := GetJobsByDesignerOrProducerId(jobIdHex, producerId, "", 10, 0, mt.Client)
foundJob, err := GetJobsByDesignerOrProducerId(jobIdHex, producerId, "", "", 10, 0, mt.Client)

assert.Nil(err)
assert.Equal(foundJob, []schema.JobView{expectedJob})
Expand Down Expand Up @@ -967,7 +967,7 @@ func TestGetJobsByDesignerOrProducerId(t *testing.T) {
mt.AddMockResponses(res, end)

// Assertions
foundJob, err := GetJobsByDesignerOrProducerId(designerId, jobIdHex, "", 10, 0, mt.Client)
foundJob, err := GetJobsByDesignerOrProducerId(designerId, jobIdHex, "", "", 10, 0, mt.Client)

assert.Nil(err)
assert.Equal(foundJob, []schema.JobView{expectedJob})
Expand Down
2 changes: 2 additions & 0 deletions backend/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ type Job struct {
PotentialProducers []primitive.ObjectID `bson:"potentialProducers,omitempty" json:"potentialProducers"`
LastUpdated time.Time `bson:"lastUpdated,omitempty" json:"lastUpdated"`
// lastUpdated represents last time a potential producer was added
TrackingNumber string `bson:"trackingNumber,omitempty" json:"trackingNumber"`
EstimatedDelivery time.Time `bson:"estimatedDelivery,omitempty" json:"estimatedDelivery"`
}

type JobView struct {
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/api/jobAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export const createJobApi = (baseUrl: string) =>
url: `/${jobId}`,
}),
}),
getJobById: builder.query<Job, string>({
query: (id) => `/${id}`,
}),
deleteJob: builder.mutation<Design, string>({
query: (jobId) => ({
method: "DELETE",
Expand Down Expand Up @@ -58,9 +61,9 @@ export const createJobApi = (baseUrl: string) =>
}),
getDesignerJobs: builder.query<
Job[],
{ designerId: string; page: string }
{ designerId: string; page: string; sort: string }
>({
query: ({ designerId, page }) => `?designer=${designerId}&page=${page}`,
query: ({ designerId, page, sort }) => `?designer=${designerId}&page=${page}&sort=${sort}`,
}),
getDesignerJobsFiltered: builder.query<
Job[],
Expand Down
40 changes: 40 additions & 0 deletions frontend/src/components/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Avatar } from "@mui/material"
import { StyledAvatarProps } from "./Avatar.types"

export default function StyledAvatar({ userType, firstName, lastName, innerHeight, innerWidth, outerWidth, outerHeight, offset }: StyledAvatarProps) {

const colors = {
"outer": "",
"inner": "#FFFFFF"
}

if (userType == "PRODUCER" || userType == "producer") {
colors["outer"] = "#00baef"
} else {
colors["outer"] = "#efaf00"
}

if (!firstName || !lastName) {
return (
<Avatar sx={{ width: outerWidth, height: outerHeight, color: colors['outer'], backgroundColor: colors['outer'] }}>
<Avatar sx={{ width: innerWidth+offset, height: innerHeight+offset, color: colors['inner'], backgroundColor: colors['inner'] }}>
<Avatar sx={{ width: innerWidth, height: innerHeight }} />
</Avatar>
</Avatar>
)

}

const initials = firstName.charAt(0).toUpperCase() + lastName.charAt(0).toUpperCase()

return (
<Avatar sx={{ width: outerWidth, height: outerHeight, color: colors['outer'], backgroundColor: colors['outer'] }}>
<Avatar sx={{ width: innerWidth+offset, height: innerHeight+offset, color: colors['inner'], backgroundColor: colors['inner'] }}>
<Avatar sx={{ width: innerWidth, height: innerHeight }}>
{initials}
</Avatar>
</Avatar>
</Avatar>
)

}
11 changes: 11 additions & 0 deletions frontend/src/components/Avatar/Avatar.types.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export interface StyledAvatarProps {
userType?: string;
firstName?: string;
lastName?: string;
innerHeight: number;
innerWidth: number;
outerWidth: number;
outerHeight: number;
// offset represents the amount of whitespace going outwards from the inner avatar
offset: number;
}
50 changes: 0 additions & 50 deletions frontend/src/components/Jobs/AvatarCell.tsx

This file was deleted.

1 change: 1 addition & 0 deletions frontend/src/components/Jobs/DesignerJobs/JobsDesigner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default function JobsDesigner() {
const jobsResponse = jobApi.useGetDesignerJobsQuery({
designerId: user.id,
page: "0",
sort: ""
});

useEffect(() => {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/Jobs/JobRow.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TableCell, TableRow } from "@mui/material";
import { Job } from "../../main.types";
import { ReactNode } from "react";
import AvatarCell from "./AvatarCell";
import ProducerCell from "./ProducerCell";
import StyledButton from "../Button/Button";
import { userApi } from "../../api/api";

Expand Down Expand Up @@ -68,7 +68,7 @@ export default function JobRow({ job, type }: JobRowProps) {
}}
>
<JobTableCell size='lg'>
<AvatarCell
<ProducerCell
userType={type}
firstName={name?.firstName}
lastName={name?.lastName}
Expand Down
24 changes: 24 additions & 0 deletions frontend/src/components/Jobs/ProducerCell.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import StyledAvatar from "../Avatar/Avatar";

type ProducerCellProps = {
avatar?: string,
firstName?: string,
lastName?: string,
userType: 'designer' | 'producer'
}

export default function ProducerCell({ firstName, lastName, userType } : ProducerCellProps) {

return (
<div className="flex items-center text-base">
<StyledAvatar userType={userType} firstName={firstName} lastName={lastName} outerWidth={48} outerHeight={48} innerHeight={40} innerWidth={40} offset={4} />
<div className=" pl-4">
{(firstName && lastName)
? firstName + " " + lastName
: userType === "producer"
? "Pending"
: "User Not Found"}
</div>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { userApi } from "../../../../api/api";
import { Job } from "../../../../main.types";
import { Avatar } from "@mui/material";
import JobAcceptButtons from "./JobAcceptButtons";
import { Skeleton } from "@mui/material";
import StyledAvatar from "../../../Avatar/Avatar";

function capitalize(str?: string) {
return str ? str[0].toUpperCase() + str.slice(1).toLowerCase() : "";
Expand All @@ -15,17 +15,16 @@ export default function DesignerName(props: { designerId: string; job?: Job }) {
<div className=" flex flex-row items-center justify-between w-full">
<div className=" flex flex-row">
{data ? (
<Avatar
className={`outline outline-4 outline-offset-2 !w-24 !h-24 ${
data.userType == "DESIGNER"
? "outline-designer"
: "outline-producer"
}`}
alt={`${data.firstName} ${data.lastName}`}
sx={{ width: 64, height: 64 }}
>
{data.firstName.charAt(0)}
</Avatar>
<StyledAvatar
userType={data.userType}
firstName={data.firstName}
lastName={data.lastName}
innerWidth={80}
innerHeight={80}
outerHeight={96}
outerWidth={96}
offset={8}
/>
) : (
<Skeleton variant="circular" width={64} height={64} />
)}
Expand Down
Loading