add react-query
This commit is contained in:
27
frontend/package-lock.json
generated
27
frontend/package-lock.json
generated
@@ -14,6 +14,7 @@
|
|||||||
"@mantine/hooks": "^8.3.14",
|
"@mantine/hooks": "^8.3.14",
|
||||||
"@tabler/icons": "^3.36.1",
|
"@tabler/icons": "^3.36.1",
|
||||||
"@tabler/icons-react": "^3.36.1",
|
"@tabler/icons-react": "^3.36.1",
|
||||||
|
"@tanstack/react-query": "^5.90.20",
|
||||||
"capitalize": "^2.0.4",
|
"capitalize": "^2.0.4",
|
||||||
"dayjs": "^1.11.19",
|
"dayjs": "^1.11.19",
|
||||||
"i18next": "^25.8.4",
|
"i18next": "^25.8.4",
|
||||||
@@ -1529,6 +1530,32 @@
|
|||||||
"react": ">= 16"
|
"react": ">= 16"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@tanstack/query-core": {
|
||||||
|
"version": "5.90.20",
|
||||||
|
"resolved": "https://registry.npmjs.org/@tanstack/query-core/-/query-core-5.90.20.tgz",
|
||||||
|
"integrity": "sha512-OMD2HLpNouXEfZJWcKeVKUgQ5n+n3A2JFmBaScpNDUqSrQSjiveC7dKMe53uJUg1nDG16ttFPz2xfilz6i2uVg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"funding": {
|
||||||
|
"type": "github",
|
||||||
|
"url": "https://github.com/sponsors/tannerlinsley"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@tanstack/react-query": {
|
||||||
|
"version": "5.90.20",
|
||||||
|
"resolved": "https://registry.npmjs.org/@tanstack/react-query/-/react-query-5.90.20.tgz",
|
||||||
|
"integrity": "sha512-vXBxa+qeyveVO7OA0jX1z+DeyCA4JKnThKv411jd5SORpBKgkcVnYKCiBgECvADvniBX7tobwBmg01qq9JmMJw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@tanstack/query-core": "5.90.20"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"type": "github",
|
||||||
|
"url": "https://github.com/sponsors/tannerlinsley"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"react": "^18 || ^19"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@types/babel__core": {
|
"node_modules/@types/babel__core": {
|
||||||
"version": "7.20.5",
|
"version": "7.20.5",
|
||||||
"resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.5.tgz",
|
"resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.5.tgz",
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
"@mantine/hooks": "^8.3.14",
|
"@mantine/hooks": "^8.3.14",
|
||||||
"@tabler/icons": "^3.36.1",
|
"@tabler/icons": "^3.36.1",
|
||||||
"@tabler/icons-react": "^3.36.1",
|
"@tabler/icons-react": "^3.36.1",
|
||||||
|
"@tanstack/react-query": "^5.90.20",
|
||||||
"capitalize": "^2.0.4",
|
"capitalize": "^2.0.4",
|
||||||
"dayjs": "^1.11.19",
|
"dayjs": "^1.11.19",
|
||||||
"i18next": "^25.8.4",
|
"i18next": "^25.8.4",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Group, NumberInput, Paper, Stack, Text } from "@mantine/core";
|
import { Group, NumberInput, Paper, Stack, Text } from "@mantine/core";
|
||||||
import { useCallback, useState, type RefAttributes } from "react";
|
import { useCallback, useState } from "react";
|
||||||
|
|
||||||
type Product = {
|
type Product = {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -17,7 +17,6 @@ export type ShipmentCardProps = {
|
|||||||
export default function ShipmentCard({title, date, product}: ShipmentCardProps) {
|
export default function ShipmentCard({title, date, product}: ShipmentCardProps) {
|
||||||
|
|
||||||
const [ price, setPrice ] = useState<number>(0)
|
const [ price, setPrice ] = useState<number>(0)
|
||||||
|
|
||||||
const calculatePrice = useCallback((value: number | string ) => {
|
const calculatePrice = useCallback((value: number | string ) => {
|
||||||
const numberValue = Number(value)
|
const numberValue = Number(value)
|
||||||
const price = numberValue * product.price
|
const price = numberValue * product.price
|
||||||
|
|||||||
@@ -4,11 +4,16 @@ import { RouterProvider } from "react-router";
|
|||||||
import { router } from "./router.tsx";
|
import { router } from "./router.tsx";
|
||||||
import { MantineProvider } from "@mantine/core";
|
import { MantineProvider } from "@mantine/core";
|
||||||
import '@mantine/core/styles.css';
|
import '@mantine/core/styles.css';
|
||||||
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||||
|
|
||||||
|
const queryClient = new QueryClient()
|
||||||
|
|
||||||
createRoot(document.getElementById("root")!).render(
|
createRoot(document.getElementById("root")!).render(
|
||||||
<StrictMode>
|
<StrictMode>
|
||||||
<MantineProvider>
|
<QueryClientProvider client={queryClient}>
|
||||||
<RouterProvider router={router} />
|
<MantineProvider>
|
||||||
</MantineProvider>
|
<RouterProvider router={router} />
|
||||||
|
</MantineProvider>
|
||||||
|
</QueryClientProvider>
|
||||||
</StrictMode>
|
</StrictMode>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,8 +2,11 @@ import { Flex, Grid, Select, Stack, Text, TextInput, Title } from "@mantine/core
|
|||||||
import { t } from "../../config/i18n";
|
import { t } from "../../config/i18n";
|
||||||
import { IconUser } from "@tabler/icons-react";
|
import { IconUser } from "@tabler/icons-react";
|
||||||
import ShipmentCard from "../../components/ShipmentCard";
|
import ShipmentCard from "../../components/ShipmentCard";
|
||||||
|
import { getForm } from "../../services/api";
|
||||||
|
|
||||||
export function ContractForm() {
|
export function ContractForm() {
|
||||||
|
const { isPending, error, data } = getForm(1);
|
||||||
|
console.log(isPending, error, data);
|
||||||
return (
|
return (
|
||||||
<Flex
|
<Flex
|
||||||
w={{base: "100%", sm: "50%", lg: "60%"}}
|
w={{base: "100%", sm: "50%", lg: "60%"}}
|
||||||
@@ -50,11 +53,13 @@ export function ContractForm() {
|
|||||||
</Stack>
|
</Stack>
|
||||||
<Stack>
|
<Stack>
|
||||||
<Text>{t("products reccurent phase")}</Text>
|
<Text>{t("products reccurent phase")}</Text>
|
||||||
|
{isPending ||
|
||||||
<Select
|
<Select
|
||||||
label={`${t("select reccurent product")} (${t("this product will be distributed for all shipments")})`}
|
label={`${t("select reccurent product")} (${t("this product will be distributed for all shipments")})`}
|
||||||
placeholder={t("select reccurent product")}
|
placeholder={t("select reccurent product")}
|
||||||
data={["qwe", "qweqwe", "qweqweqwe"]}
|
data={data?.productor?.products.map(el=> el.name)}
|
||||||
/>
|
/>
|
||||||
|
}
|
||||||
</Stack>
|
</Stack>
|
||||||
<Stack>
|
<Stack>
|
||||||
<Text>{t("products planned phase")}</Text>
|
<Text>{t("products planned phase")}</Text>
|
||||||
|
|||||||
10
frontend/src/services/api.ts
Normal file
10
frontend/src/services/api.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
|
||||||
|
export function getForm(id: number) {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ['form'],
|
||||||
|
queryFn: () => (
|
||||||
|
fetch(`http://localhost:8000/forms/${id}`).then((res) => res.json())
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user