Skip to content

Commit

Permalink
fix button not being trigerred after clicking once and fix products n…
Browse files Browse the repository at this point in the history
…ot being displayed properly in grid
  • Loading branch information
radekm2000 committed Apr 20, 2024
1 parent ee9e611 commit ff46dbf
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 24 deletions.
2 changes: 1 addition & 1 deletion client/ecommerce/src/api/axios.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { RequestAccessTokenInterceptor } from "./request-access-token.intercepto
import { ResponseOAuthInterceptor } from "./response-auth.interceptor";
import { FeedbackFormData } from "../components/FeedbackDialog";
import { ResponseErrorInterceptor } from "./responseError.interceptor";
const LIMIT = 5;
const LIMIT = 8;
const baseUrl = "http://localhost:3000";
// if (import.meta.env.VITE_NETLIFY == "true") {
// baseUrl = "https://ecommerce-123.onrender.com";
Expand Down
7 changes: 5 additions & 2 deletions client/ecommerce/src/components/DisplayAdminNotifications.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { AdminNotification } from "../types/types";
import { Box, Divider, Typography } from "@mui/material";
import { formatDistanceToNowStrict } from "date-fns";
import { compareDesc, formatDistanceToNowStrict } from "date-fns";
import { Link } from "wouter";

const DisplayAdminNotifications = ({
adminNotifications,
}: {
adminNotifications: AdminNotification[];
}) => {
const timeFormattedAdminNotifications = adminNotifications.map(
const sortNotificationsByCreationTime = adminNotifications.sort((a, b) =>
compareDesc(a.createdAt, b.createdAt)
);
const timeFormattedAdminNotifications = sortNotificationsByCreationTime.map(
(notification) => {
const formattedTime = formatDistanceToNowStrict(notification.createdAt, {
addSuffix: true,
Expand Down
21 changes: 12 additions & 9 deletions client/ecommerce/src/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ export const Navbar = () => {
setMobileMoreAnchorEl(event.currentTarget);
};

const onButtonClick = () => {
setLocation("/products/new", { replace: true });
};

const menuId = "primary-search-account-menu";
const shownNotificationsInboxNumber = notificationsReceived.filter(
(notification) => notification.isRead !== true
Expand Down Expand Up @@ -394,6 +398,7 @@ export const Navbar = () => {
))}

<Button
onClick={onButtonClick}
sx={{
borderRadius: "6px",
background: "#007782",
Expand All @@ -405,15 +410,13 @@ export const Navbar = () => {
display: below800 ? "none" : null,
}}
>
<Link href="/products/new">
<Typography
color="white"
fontFamily="Maison Neue"
fontSize="14px"
>
Sell now
</Typography>
</Link>
<Typography
color="white"
fontFamily="Maison Neue"
fontSize="14px"
>
Sell now
</Typography>
</Button>

<Box sx={{ display: { xs: "none", md: "flex", gap: "5px" } }}>
Expand Down
14 changes: 4 additions & 10 deletions client/ecommerce/src/components/PaginatedProducts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,10 @@ export const PaginatedProducts = () => {
<Grid
item
key={index}
lg={below1200 ? 3 : 12 / 5}
md={below1200 ? 3 : 3}
xs={below700 ? 6 : 4}
xl={
page.data.length == 2 || page.data.length == 1
? 6
: page.data.length >= 4
? 3
: 4
}
lg={3}
md={below1200 ? 4 : 3}
xs={below700 ? 12 : 6}
xl={3}
>
<Card
elevation={0}
Expand Down
3 changes: 3 additions & 0 deletions client/ecommerce/src/hooks/useAddAdminNotification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ export const useAddAdminNotification = () => {
return useMutation({
mutationKey: ["admin-notifications"],
mutationFn: addAdminNotification,
onSuccess: (data) => {
console.log(data);
},
onError: (err) => {
console.log(err);
},
Expand Down
10 changes: 8 additions & 2 deletions server/ecommerce/src/products/products.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable } from '@nestjs/common';
import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Product } from 'src/utils/entities/product.entity';
import { ILike, Repository } from 'typeorm';
Expand Down Expand Up @@ -31,13 +31,16 @@ const s3 = new S3Client({
});
@Injectable()
export class ProductsService {
logger: Logger;
constructor(
@InjectRepository(Product) private productRepository: Repository<Product>,
private productsNotificationService: ProductNotificationService,
@InjectRepository(Image)
private readonly imageRepository: Repository<Image>,
private usersService: UsersService,
) {}
) {
this.logger = new Logger(ProductsService.name);
}

async findProduct(productId: number) {
const product = await this.productRepository.findOne({
Expand Down Expand Up @@ -328,6 +331,9 @@ export class ProductsService {
} catch (error) {
return 'Failed uploading image to s3 bucket';
}
this.logger.log(
`User ${existingUser.username} added product with id ${newProduct.id}`,
);
return;
}

Expand Down

0 comments on commit ff46dbf

Please sign in to comment.