feat: add navigation keys and routing check (#24)
All checks were successful
it-academy/dry-wash-pl/pipeline/head This commit looks good

This commit is contained in:
RustamRu 2024-11-16 15:41:14 +03:00
parent 3ade6f83cc
commit cba5beda72
9 changed files with 66 additions and 14 deletions

9
package-lock.json generated
View File

@ -9,7 +9,7 @@
"version": "0.0.0", "version": "0.0.0",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@brojs/cli": "^1.6.1", "@brojs/cli": "^1.6.2",
"@chakra-ui/icons": "^2.2.4", "@chakra-ui/icons": "^2.2.4",
"@chakra-ui/react": "^2.4.2", "@chakra-ui/react": "^2.4.2",
"@emotion/react": "^11.4.1", "@emotion/react": "^11.4.1",
@ -1564,9 +1564,10 @@
} }
}, },
"node_modules/@brojs/cli": { "node_modules/@brojs/cli": {
"version": "1.6.1", "version": "1.6.2",
"resolved": "https://git.bro-js.ru/api/packages/bro-js/npm/%40brojs%2Fcli/-/1.6.1/cli-1.6.1.tgz", "resolved": "https://git.bro-js.ru/api/packages/bro-js/npm/%40brojs%2Fcli/-/1.6.2/cli-1.6.2.tgz",
"integrity": "sha512-jcRv68xUxQKYdVOH+eFcuV2DquOU1qHqduozghho02aGNUN8/oB2RL5WQ8ssi4wPJ+HpwRpmpqcqQAnnb9F7Cg==", "integrity": "sha512-IDGX5SMt1VQxW2TfY6onazeSjQgUaRut4rwRZVWgBfzHrdp7cHgobciQkF65baT8SfAeaM3w/XHaQr8X1VKGEg==",
"license": "ISC",
"dependencies": { "dependencies": {
"@brojs/dev-server": "^1.6.1", "@brojs/dev-server": "^1.6.1",
"@brojs/fire.app": "^1.6.1", "@brojs/fire.app": "^1.6.1",

View File

@ -17,7 +17,7 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@brojs/cli": "^1.6.1", "@brojs/cli": "^1.6.2",
"@chakra-ui/icons": "^2.2.4", "@chakra-ui/icons": "^2.2.4",
"@chakra-ui/react": "^2.4.2", "@chakra-ui/react": "^2.4.2",
"@emotion/react": "^11.4.1", "@emotion/react": "^11.4.1",

24
src/__data__/urls.ts Normal file
View File

@ -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 });
}
}
};

View File

@ -1,10 +1,11 @@
import React, { FC } from 'react'; import React, { FC } from 'react';
import { Link as RouterLink } from 'react-router-dom'; import { Link as RouterLink } from 'react-router-dom';
import { ButtonProps, Button } from '@chakra-ui/react'; import { ButtonProps, Button } from '@chakra-ui/react';
import { URLs } from '../../../__data__/urls';
export const CtaButton: FC<ButtonProps> = (props) => { export const CtaButton: FC<ButtonProps> = (props) => {
return ( return (
<Button as={RouterLink} to='/dry-wash/order-form' colorScheme='primary' {...props}> <Button as={RouterLink} to={URLs.orderForm.getUrl()} colorScheme='primary' {...props}>
Сделать заказ Сделать заказ
</Button> </Button>
); );

View File

@ -1,3 +1,5 @@
import { Order } from "../../models";
type ReviewItem = { type ReviewItem = {
id: string; id: string;
firstname: string; firstname: string;
@ -32,3 +34,9 @@ export const mockReviews: ReviewItem[] = [
text: "К сожалению, мой опыт с сухой мойкой автомобилей оказался неудачным. Ожидала увидеть чистую машину после процедуры, но многие участки остались незаделанными. Кроме того, процедура заняла больше времени, чем мне обещали. Возможно, в этом конкретном центре что-то пошло не так, но я бы не стала повторно обращаться за этой услугой." text: "К сожалению, мой опыт с сухой мойкой автомобилей оказался неудачным. Ожидала увидеть чистую машину после процедуры, но многие участки остались незаделанными. Кроме того, процедура заняла больше времени, чем мне обещали. Возможно, в этом конкретном центре что-то пошло не так, но я бы не стала повторно обращаться за этой услугой."
}, },
].map((data, i) => ({ id: `review${i}`, ...data })); ].map((data, i) => ({ id: `review${i}`, ...data }));
export const mockOrders: Order.View[] = [
{ id: 'id1' },
{ id: 'id2' },
{ id: 'id3' },
];

1
src/models/index.ts Normal file
View File

@ -0,0 +1 @@
export * as Order from './order';

5
src/models/order.ts Normal file
View File

@ -0,0 +1,5 @@
export type Id = string;
export type View = {
id: Id;
};

View File

@ -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 = () => { const Page = () => {
return <h1>Order form </h1>; return (
<>
<h1>Order form</h1>
{mockOrders.map(({ id }) => (
<Button key={id} as={RouterLink} to={URLs.orderView.getUrl(id)}>
Посмотреть заказ {id}
</Button>
))}
</>
);
}; };
export default Page; export default Page;

View File

@ -2,6 +2,7 @@ import React, { lazy, Suspense } from 'react';
import { Routes, Route } from 'react-router-dom'; import { Routes, Route } from 'react-router-dom';
import { PageSpinner } from './components'; import { PageSpinner } from './components';
import Arm from './pages/arm'; import Arm from './pages/arm';
import { URLs } from './__data__/urls';
const Landing = lazy(() => import('./pages/landing')); const Landing = lazy(() => import('./pages/landing'));
const OrderForm = lazy(() => import('./pages/order-form')); const OrderForm = lazy(() => import('./pages/order-form'));
@ -11,11 +12,9 @@ const Routers = () => {
return ( return (
<Suspense fallback={<PageSpinner />}> <Suspense fallback={<PageSpinner />}>
<Routes> <Routes>
<Route path='/dry-wash'> <Route path={URLs.landing.url} element={<Landing />} />
<Route index element={<Landing />} /> <Route path={URLs.orderForm.url} element={<OrderForm />} />
<Route path='order-form' element={<OrderForm />} /> <Route path={URLs.orderView.url} element={<OrderView />} />
<Route path='order-view' element={<OrderView />} />
</Route>
<Route path='/dry-wash/arm' element={<Arm />}></Route> <Route path='/dry-wash/arm' element={<Arm />}></Route>
</Routes> </Routes>
</Suspense> </Suspense>