From cba5beda72d81050056c51e741faa995a154dcfc Mon Sep 17 00:00:00 2001 From: RustamRu Date: Sat, 16 Nov 2024 15:41:14 +0300 Subject: [PATCH] feat: add navigation keys and routing check (#24) --- package-lock.json | 9 +++---- package.json | 2 +- src/__data__/urls.ts | 24 +++++++++++++++++++ .../landing/CtaButton/CtaButton.tsx | 3 ++- src/mocks/landing/index.ts | 10 +++++++- src/models/index.ts | 1 + src/models/order.ts | 5 ++++ src/pages/order-form/index.tsx | 17 +++++++++++-- src/routes.tsx | 9 ++++--- 9 files changed, 66 insertions(+), 14 deletions(-) create mode 100644 src/__data__/urls.ts create mode 100644 src/models/index.ts create mode 100644 src/models/order.ts diff --git a/package-lock.json b/package-lock.json index 4e4f5b7..2ff06ca 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.0.0", "license": "ISC", "dependencies": { - "@brojs/cli": "^1.6.1", + "@brojs/cli": "^1.6.2", "@chakra-ui/icons": "^2.2.4", "@chakra-ui/react": "^2.4.2", "@emotion/react": "^11.4.1", @@ -1564,9 +1564,10 @@ } }, "node_modules/@brojs/cli": { - "version": "1.6.1", - "resolved": "https://git.bro-js.ru/api/packages/bro-js/npm/%40brojs%2Fcli/-/1.6.1/cli-1.6.1.tgz", - "integrity": "sha512-jcRv68xUxQKYdVOH+eFcuV2DquOU1qHqduozghho02aGNUN8/oB2RL5WQ8ssi4wPJ+HpwRpmpqcqQAnnb9F7Cg==", + "version": "1.6.2", + "resolved": "https://git.bro-js.ru/api/packages/bro-js/npm/%40brojs%2Fcli/-/1.6.2/cli-1.6.2.tgz", + "integrity": "sha512-IDGX5SMt1VQxW2TfY6onazeSjQgUaRut4rwRZVWgBfzHrdp7cHgobciQkF65baT8SfAeaM3w/XHaQr8X1VKGEg==", + "license": "ISC", "dependencies": { "@brojs/dev-server": "^1.6.1", "@brojs/fire.app": "^1.6.1", diff --git a/package.json b/package.json index 0778b8c..74832ac 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "author": "", "license": "ISC", "dependencies": { - "@brojs/cli": "^1.6.1", + "@brojs/cli": "^1.6.2", "@chakra-ui/icons": "^2.2.4", "@chakra-ui/react": "^2.4.2", "@emotion/react": "^11.4.1", diff --git a/src/__data__/urls.ts b/src/__data__/urls.ts new file mode 100644 index 0000000..0cbff49 --- /dev/null +++ b/src/__data__/urls.ts @@ -0,0 +1,24 @@ +import { generatePath } from "react-router-dom"; +import { getNavigationValue } from "@brojs/cli"; +import { Order } from "../models"; + +export const URLs = { + landing: { + url: getNavigationValue("dry-wash.main"), + getUrl() { + return this.url; + } + }, + orderForm: { + url: getNavigationValue("dry-wash.create"), + getUrl() { + return this.url; + } + }, + orderView: { + url: getNavigationValue("dry-wash.view.order"), + getUrl(orderId: Order.Id) { + return generatePath(this.url, { orderId }); + } + } +}; \ No newline at end of file diff --git a/src/components/landing/CtaButton/CtaButton.tsx b/src/components/landing/CtaButton/CtaButton.tsx index a1168f3..a1bb9a2 100644 --- a/src/components/landing/CtaButton/CtaButton.tsx +++ b/src/components/landing/CtaButton/CtaButton.tsx @@ -1,10 +1,11 @@ import React, { FC } from 'react'; import { Link as RouterLink } from 'react-router-dom'; import { ButtonProps, Button } from '@chakra-ui/react'; +import { URLs } from '../../../__data__/urls'; export const CtaButton: FC = (props) => { return ( - ); diff --git a/src/mocks/landing/index.ts b/src/mocks/landing/index.ts index e6862bc..9c94b8a 100644 --- a/src/mocks/landing/index.ts +++ b/src/mocks/landing/index.ts @@ -1,3 +1,5 @@ +import { Order } from "../../models"; + type ReviewItem = { id: string; firstname: string; @@ -31,4 +33,10 @@ export const mockReviews: ReviewItem[] = [ picture: 'https://img.freepik.com/free-photo/portrait-young-blonde-woman-with-plait-polka-dot-blouse_273609-10490.jpg', text: "К сожалению, мой опыт с сухой мойкой автомобилей оказался неудачным. Ожидала увидеть чистую машину после процедуры, но многие участки остались незаделанными. Кроме того, процедура заняла больше времени, чем мне обещали. Возможно, в этом конкретном центре что-то пошло не так, но я бы не стала повторно обращаться за этой услугой." }, -].map((data, i) => ({ id: `review${i}`, ...data })); \ No newline at end of file +].map((data, i) => ({ id: `review${i}`, ...data })); + +export const mockOrders: Order.View[] = [ + { id: 'id1' }, + { id: 'id2' }, + { id: 'id3' }, +]; \ No newline at end of file diff --git a/src/models/index.ts b/src/models/index.ts new file mode 100644 index 0000000..21468eb --- /dev/null +++ b/src/models/index.ts @@ -0,0 +1 @@ +export * as Order from './order'; \ No newline at end of file diff --git a/src/models/order.ts b/src/models/order.ts new file mode 100644 index 0000000..5cd62d9 --- /dev/null +++ b/src/models/order.ts @@ -0,0 +1,5 @@ +export type Id = string; + +export type View = { + id: Id; +}; \ No newline at end of file diff --git a/src/pages/order-form/index.tsx b/src/pages/order-form/index.tsx index beba6a6..0caf395 100644 --- a/src/pages/order-form/index.tsx +++ b/src/pages/order-form/index.tsx @@ -1,7 +1,20 @@ -import React from "react"; +import React from 'react'; +import { Link as RouterLink } from 'react-router-dom'; +import { Button } from '@chakra-ui/react'; +import { URLs } from '../../__data__/urls'; +import { mockOrders } from '../../mocks/landing'; const Page = () => { - return

Order form

; + return ( + <> +

Order form

+ {mockOrders.map(({ id }) => ( + + ))} + + ); }; export default Page; diff --git a/src/routes.tsx b/src/routes.tsx index ab2dbfa..04fee2a 100644 --- a/src/routes.tsx +++ b/src/routes.tsx @@ -2,6 +2,7 @@ import React, { lazy, Suspense } from 'react'; import { Routes, Route } from 'react-router-dom'; import { PageSpinner } from './components'; import Arm from './pages/arm'; +import { URLs } from './__data__/urls'; const Landing = lazy(() => import('./pages/landing')); const OrderForm = lazy(() => import('./pages/order-form')); @@ -11,11 +12,9 @@ const Routers = () => { return ( }> - - } /> - } /> - } /> - + } /> + } /> + } /> }>