Skip to content

Commit

Permalink
th-81: Create order card component (BinaryStudioAcademy#95)
Browse files Browse the repository at this point in the history
* th-81: + order card

* th-81: * Migrated to camelCase class names, optimized import in styles.module.css

* th-81: * moved svg to ~/assets/img/order-card; fixed imports; added types for parts of order-card props

* th-191: * fixed locations displacement

* th-81: * Merged development
  • Loading branch information
mV22110702 committed Sep 9, 2023
1 parent 435c184 commit 16ff681
Show file tree
Hide file tree
Showing 26 changed files with 1,077 additions and 9 deletions.
5 changes: 5 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
"@hookform/resolvers": "2.9.11",
"@reduxjs/toolkit": "1.9.3",
"@tanstack/react-table": "8.9.3",
"@rollup/pluginutils": "5.0.4",
"@svgr/core": "8.1.0",
"clsx": "2.0.0",
"modern-normalize": "2.0.0",
"react": "18.2.0",
Expand All @@ -34,6 +36,9 @@
"react-redux": "8.1.2",
"react-router-dom": "6.8.2",
"react-select": "5.7.4",
"react-select": "5.7.4",
"react-toastify": "9.1.3",
"vite-plugin-svgr": "3.2.0",
"react-toastify": "9.1.3",
"socket.io-client": "4.7.2"
},
Expand Down
7 changes: 7 additions & 0 deletions frontend/react-component.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
declare module '*.svg' {
import React = require('react');

const ReactComponent: React.FC<React.SVGProps<SVGSVGElement>>;

export { ReactComponent };
}
3 changes: 3 additions & 0 deletions frontend/src/assets/img/order-card/arrow-down.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions frontend/src/assets/img/order-card/blue-circle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions frontend/src/assets/img/order-card/horizontal-bar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions frontend/src/assets/img/order-card/location-dot.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions frontend/src/assets/img/order-card/map.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions frontend/src/assets/img/order-card/red-circle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion frontend/src/libs/components/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ export { Link } from './link/link.js';
export { LocationInput } from './location-input/location-input.js';
export { Modal } from './modal/modal.js';
export { Notification } from './notification/notification.js';
export { OrderCard } from './order-card/order-card.js';
export { PageLayout } from './page-layout/page-layout.js';
export { Pagination } from './pagination/pagination.js';
export { PlainSvgIcon } from './plain-svg-icon/plain-svg-icon.js';
export { ProtectedRoute } from './protected-route/protected-route.js';
export { Radio } from './radio/radio.js';
export { Router } from './router/router.jsx';
export { RouterProvider } from './router-provider/router-provider.jsx';
export { RouterProvider } from './router-provider/router-provider.js';
export { Spinner } from './spinner/spinner.js';
export { StarRating } from './star-rating/star-rating.jsx';
export { Table } from './table/table.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type DriverProfileInfo = {
firstName: string;
lastName: string;
profileURL: string;
};

export { type DriverProfileInfo };
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type OrderCurrentStatus = {
timespanLastUpdated: string;
location: string;
distanceLeft: number;
timespanLeft: string;
};

export { type OrderCurrentStatus };
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type OrderInitialStatus = {
startLocation: string;
endLocation: string;
};

export { type OrderInitialStatus };
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type OrderedTruckInfo = {
licensePlate: string;
};

export { type OrderedTruckInfo };
4 changes: 4 additions & 0 deletions frontend/src/libs/components/order-card/libs/types/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export { type DriverProfileInfo } from './driver-profile-info.type.js';
export { type OrderCurrentStatus } from './order-current-status.type.js';
export { type OrderInitialStatus } from './order-initial-status.type.js';
export { type OrderedTruckInfo } from './ordered-truck-info.type.js';
123 changes: 123 additions & 0 deletions frontend/src/libs/components/order-card/order-card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import { PlainSvgIconName } from '~/libs/enums/enums.js';
import { getValidClassNames } from '~/libs/helpers/helpers.js';

import { PlainSvgIcon } from '../plain-svg-icon/plain-svg-icon.js';
import {
type DriverProfileInfo,
type OrderCurrentStatus,
type OrderedTruckInfo,
type OrderInitialStatus,
} from './libs/types/types.js';
import styles from './styles.module.scss';

type Properties = {
driver: DriverProfileInfo;
truck: OrderedTruckInfo;
initialStatus: OrderInitialStatus;
currentStatus: OrderCurrentStatus;
};

const OrderCard: React.FC<Properties> = ({
driver: { firstName, lastName, profileURL },
truck: { licensePlate },
initialStatus: { startLocation, endLocation },
currentStatus: { timespanLastUpdated, location, distanceLeft, timespanLeft },
}: Properties) => {
const areManyKilometers = distanceLeft > 1;

return (
<div className={styles.container}>
<div className={styles.cardLayout}>
<div className={styles.horizontalBar}>
<div>
<PlainSvgIcon name={PlainSvgIconName.HORIZONTAL_BAR} />
</div>
</div>
<div className={styles.header}>
<div className={styles.headerImageContainer}>
<img
className={styles.profileImage}
src={profileURL}
alt="header"
/>
</div>
<div className={styles.headerInfoContainer}>
<div className={styles.headerTitleContainer}>
<span className="text-md">
{firstName} {lastName}
</span>
</div>
<div className={styles.headerSubtitleContainer}>
<span className={getValidClassNames(styles.subtitle, 'text-sm')}>
{licensePlate}
</span>
</div>
</div>
</div>
<div className={styles.body}>
<div className={styles.bodyContent}>
<div className={styles.locationDot}>
<PlainSvgIcon name={PlainSvgIconName.LOCATION_DOT} />
</div>
<span className={getValidClassNames(styles.location, 'text-sm')}>
{location}
</span>
<span className={getValidClassNames(styles.lastUpdate, 'text-sm')}>
last updated {timespanLastUpdated} ago
</span>
<div
className={getValidClassNames(
styles.routeDot,
styles.routeDotStart,
)}
>
<PlainSvgIcon name={PlainSvgIconName.BLUE_CIRCLE} />
</div>
<span
className={getValidClassNames(
styles.routeInfo,
styles.routeInfoStart,
'text-sm',
)}
>
{startLocation}
</span>
<div className={styles.routeArrow}>
<PlainSvgIcon name={PlainSvgIconName.ARROW_DOWN} />
</div>
<div
className={getValidClassNames(
styles.routeDot,
styles.routeDotEnd,
)}
>
<PlainSvgIcon name={PlainSvgIconName.RED_CIRCLE} />
</div>
<span
className={getValidClassNames(
styles.routeInfo,
styles.routeInfoEnd,
)}
>
{endLocation}
</span>
<div className={styles.distanceIcon}>
<PlainSvgIcon name={PlainSvgIconName.MAP} />
</div>
<span
className={getValidClassNames(
styles.distanceInfo,
styles.distanceInfoEnd,
'text-md',
)}
>
{distanceLeft} km{areManyKilometers && 's'}, {timespanLeft}
</span>
</div>
</div>
</div>
</div>
);
};

export { OrderCard };
Loading

0 comments on commit 16ff681

Please sign in to comment.