diff --git a/front/src/components/pages/home-page/component.tsx b/front/src/components/pages/home-page/component.tsx index ca2285c..d1911b7 100644 --- a/front/src/components/pages/home-page/component.tsx +++ b/front/src/components/pages/home-page/component.tsx @@ -1,4 +1,4 @@ -import { Heading } from '@components/ui'; +import { Heading, Paragraph } from '@components/ui'; import { WindmillForm } from '@components/ux'; import { WindmillFormResponse } from '@components/ux/windmill-form'; import React, { useState } from 'react'; @@ -6,26 +6,35 @@ import React, { useState } from 'react'; import styles from './styles.module.scss'; export function HomePage() { - const [formResponse, setFormResponse] = useState({ - power: [], - image: '', - }); + const [result, setResult] = useState(null); + const [error, setError] = useState(null); - const handleFormResponse = (response: WindmillFormResponse) => { - setFormResponse(response); + const handleFormSuccess = (response: WindmillFormResponse) => { + setResult(response); + setError(null); + }; + + const handleFormFail = (message: string) => { + setError(message); + setResult(null); }; return (
- +
Result -
{formResponse.power.join(' ')}
-
- {formResponse.image && Image} -
+ {result && ( + <> +
{result.power.join(' ')}
+
+ {result.image && Image} +
+ + )} + {error && {error}}
); diff --git a/front/src/components/pages/home-page/styles.module.scss b/front/src/components/pages/home-page/styles.module.scss index c19ed2c..16eb3b3 100644 --- a/front/src/components/pages/home-page/styles.module.scss +++ b/front/src/components/pages/home-page/styles.module.scss @@ -12,14 +12,14 @@ } .result { - display: grid; + display: flex; + flex-direction: column; padding: 20px; border-radius: 10px; background-color: var(--clr-layer-200); box-shadow: 0px 1px 2px var(--clr-shadow-100); gap: 20px; grid-area: result; - grid-template-columns: 1fr; } .image { diff --git a/front/src/components/ux/windmill-form/component.tsx b/front/src/components/ux/windmill-form/component.tsx index f5ebbd8..8106212 100644 --- a/front/src/components/ux/windmill-form/component.tsx +++ b/front/src/components/ux/windmill-form/component.tsx @@ -1,7 +1,8 @@ import { Button, DateInput, Heading } from '@components/ui'; +import { dateToInputString } from '@utils/date'; import { Controller, useForm } from '@utils/form'; import clsx from 'clsx'; -import React from 'react'; +import React, { useState } from 'react'; import { downloadImage, getWindmillData } from 'src/api'; import { WindmillTable } from '../windmill-table'; @@ -10,20 +11,53 @@ import styles from './styles.module.scss'; import { WindmillFormProps, WindmillFormStore } from './types'; export function WindmillForm({ - onResponse, + onSuccess, + onFail, className, ...props }: WindmillFormProps) { + const [pending, setPending] = useState(false); const { control, reset, getValues } = useForm({ initialValues, }); const classNames = clsx(className, styles.form); + const date = dateToInputString(new Date()); + + const validate = (values: Partial) => { + if (!values.dateFrom) { + onFail('Field "from" is required'); + return false; + } + if (!values.dateTo) { + onFail('Field "to" is required'); + return false; + } + if ( + !values.windmills?.length || + values.windmills.some((r) => !r.x || !r.y) + ) { + onFail('The table is filled incorrectly'); + return false; + } + return true; + }; const handleSubmit = async (event: React.FormEvent) => { event.preventDefault(); - const res = await getWindmillData(getValues()); - const image = await downloadImage(res.file_name); - onResponse({ power: res.data, image: URL.createObjectURL(image) }); + const values = getValues(); + if (!validate(values)) { + return; + } + setPending(true); + try { + const res = await getWindmillData(values); + const image = await downloadImage(res.file_name); + onSuccess({ power: res.data, image: URL.createObjectURL(image) }); + } catch { + onFail('Fetch error'); + } finally { + setPending(false); + } }; const handleResetButtonClick = () => { @@ -36,11 +70,15 @@ export function WindmillForm({
} + render={(params) => ( + + )} /> } + render={(params) => ( + + )} />
} />
- + diff --git a/front/src/components/ux/windmill-form/types.ts b/front/src/components/ux/windmill-form/types.ts index eac420e..10020fb 100644 --- a/front/src/components/ux/windmill-form/types.ts +++ b/front/src/components/ux/windmill-form/types.ts @@ -16,5 +16,6 @@ export type WindmillFormResponse = { }; export type WindmillFormProps = { - onResponse: (response: WindmillFormResponse) => void; + onSuccess: (response: WindmillFormResponse) => void; + onFail: (message: string) => void; } & React.ComponentProps<'form'>; diff --git a/front/src/utils/date/index.ts b/front/src/utils/date/index.ts new file mode 100644 index 0000000..e3365cb --- /dev/null +++ b/front/src/utils/date/index.ts @@ -0,0 +1 @@ +export * from './input'; diff --git a/front/src/utils/date/input.ts b/front/src/utils/date/input.ts new file mode 100644 index 0000000..e87c4f0 --- /dev/null +++ b/front/src/utils/date/input.ts @@ -0,0 +1,8 @@ +export const dateToInputString = (date: Date) => { + const year = date.getFullYear(); + const month = String(date.getMonth() + 1).padStart(2, '0'); + const day = String(date.getDate()).padStart(2, '0'); + const hours = String(date.getHours()).padStart(2, '0'); + const minutes = String(date.getMinutes()).padStart(2, '0'); + return `${year}-${month}-${day}T${hours}:${minutes}`; +}; diff --git a/server/public/floris/035a179e-5d97-4adc-9c04-ab029eac2c41.png b/server/public/floris/035a179e-5d97-4adc-9c04-ab029eac2c41.png new file mode 100644 index 0000000..1d6a3ba Binary files /dev/null and b/server/public/floris/035a179e-5d97-4adc-9c04-ab029eac2c41.png differ diff --git a/server/public/floris/06af7a24-8b78-4960-ab06-38d48a3f2ca3.png b/server/public/floris/06af7a24-8b78-4960-ab06-38d48a3f2ca3.png new file mode 100644 index 0000000..46d8ceb Binary files /dev/null and b/server/public/floris/06af7a24-8b78-4960-ab06-38d48a3f2ca3.png differ diff --git a/server/public/floris/0bc8cac0-7d33-4e81-8987-e83462d315d3.png b/server/public/floris/0bc8cac0-7d33-4e81-8987-e83462d315d3.png new file mode 100644 index 0000000..48a3ff0 Binary files /dev/null and b/server/public/floris/0bc8cac0-7d33-4e81-8987-e83462d315d3.png differ diff --git a/server/public/floris/16525ebd-7740-4d48-a8cf-8623b83735b6.png b/server/public/floris/16525ebd-7740-4d48-a8cf-8623b83735b6.png new file mode 100644 index 0000000..9417ebf Binary files /dev/null and b/server/public/floris/16525ebd-7740-4d48-a8cf-8623b83735b6.png differ diff --git a/server/public/floris/1a216bab-847a-47e7-b199-8ed533b8913d.png b/server/public/floris/1a216bab-847a-47e7-b199-8ed533b8913d.png new file mode 100644 index 0000000..9417ebf Binary files /dev/null and b/server/public/floris/1a216bab-847a-47e7-b199-8ed533b8913d.png differ diff --git a/server/public/floris/1ee71613-fc85-4268-9255-749c807eb019.png b/server/public/floris/1ee71613-fc85-4268-9255-749c807eb019.png new file mode 100644 index 0000000..9e0ac68 Binary files /dev/null and b/server/public/floris/1ee71613-fc85-4268-9255-749c807eb019.png differ diff --git a/server/public/floris/227aa2c8-0fe0-4c97-a76c-3b48084720d4.png b/server/public/floris/227aa2c8-0fe0-4c97-a76c-3b48084720d4.png new file mode 100644 index 0000000..ddb61c9 Binary files /dev/null and b/server/public/floris/227aa2c8-0fe0-4c97-a76c-3b48084720d4.png differ diff --git a/server/public/floris/234b2ea7-23a5-4a8d-ae77-3d1ff6c9fbfe.png b/server/public/floris/234b2ea7-23a5-4a8d-ae77-3d1ff6c9fbfe.png new file mode 100644 index 0000000..89f4743 Binary files /dev/null and b/server/public/floris/234b2ea7-23a5-4a8d-ae77-3d1ff6c9fbfe.png differ diff --git a/server/public/floris/25135ffe-fff1-43d0-ab21-9a106f66a9c8.png b/server/public/floris/25135ffe-fff1-43d0-ab21-9a106f66a9c8.png new file mode 100644 index 0000000..11ee447 Binary files /dev/null and b/server/public/floris/25135ffe-fff1-43d0-ab21-9a106f66a9c8.png differ diff --git a/server/public/floris/29b9f425-d835-4349-98fe-e8b8623e0882.png b/server/public/floris/29b9f425-d835-4349-98fe-e8b8623e0882.png new file mode 100644 index 0000000..377c46a Binary files /dev/null and b/server/public/floris/29b9f425-d835-4349-98fe-e8b8623e0882.png differ diff --git a/server/public/floris/31314a1a-5f60-476a-9f16-89319faac097.png b/server/public/floris/31314a1a-5f60-476a-9f16-89319faac097.png new file mode 100644 index 0000000..666ac6a Binary files /dev/null and b/server/public/floris/31314a1a-5f60-476a-9f16-89319faac097.png differ diff --git a/server/public/floris/355d5282-47d5-4b0b-93e0-827a079f3f5c.png b/server/public/floris/355d5282-47d5-4b0b-93e0-827a079f3f5c.png new file mode 100644 index 0000000..59b17a8 Binary files /dev/null and b/server/public/floris/355d5282-47d5-4b0b-93e0-827a079f3f5c.png differ diff --git a/server/public/floris/4a493968-6e81-4c49-afc4-22912fd8113c.png b/server/public/floris/4a493968-6e81-4c49-afc4-22912fd8113c.png new file mode 100644 index 0000000..5199ce6 Binary files /dev/null and b/server/public/floris/4a493968-6e81-4c49-afc4-22912fd8113c.png differ diff --git a/server/public/floris/5b1ea13d-614f-4c4a-8eb8-f65f5966c9a6.png b/server/public/floris/5b1ea13d-614f-4c4a-8eb8-f65f5966c9a6.png new file mode 100644 index 0000000..02ccded Binary files /dev/null and b/server/public/floris/5b1ea13d-614f-4c4a-8eb8-f65f5966c9a6.png differ diff --git a/server/public/floris/5d907710-3ac4-4807-9643-35d203c6c865.png b/server/public/floris/5d907710-3ac4-4807-9643-35d203c6c865.png new file mode 100644 index 0000000..11ee447 Binary files /dev/null and b/server/public/floris/5d907710-3ac4-4807-9643-35d203c6c865.png differ diff --git a/server/public/floris/5fa9d11b-6b0a-4446-9fee-b4e0712ed4bf.png b/server/public/floris/5fa9d11b-6b0a-4446-9fee-b4e0712ed4bf.png new file mode 100644 index 0000000..59b17a8 Binary files /dev/null and b/server/public/floris/5fa9d11b-6b0a-4446-9fee-b4e0712ed4bf.png differ diff --git a/server/public/floris/676bf294-4b74-426b-b68a-9a00f17d0933.png b/server/public/floris/676bf294-4b74-426b-b68a-9a00f17d0933.png new file mode 100644 index 0000000..1791302 Binary files /dev/null and b/server/public/floris/676bf294-4b74-426b-b68a-9a00f17d0933.png differ diff --git a/server/public/floris/7034891f-c964-4d31-9226-7da51dbad516.png b/server/public/floris/7034891f-c964-4d31-9226-7da51dbad516.png new file mode 100644 index 0000000..420f345 Binary files /dev/null and b/server/public/floris/7034891f-c964-4d31-9226-7da51dbad516.png differ diff --git a/server/public/floris/72acf344-a507-42fd-b4a1-5bb645894b03.png b/server/public/floris/72acf344-a507-42fd-b4a1-5bb645894b03.png new file mode 100644 index 0000000..47e3d90 Binary files /dev/null and b/server/public/floris/72acf344-a507-42fd-b4a1-5bb645894b03.png differ diff --git a/server/public/floris/75093389-2ac3-429a-90cf-83fe44891742.png b/server/public/floris/75093389-2ac3-429a-90cf-83fe44891742.png new file mode 100644 index 0000000..94bdf74 Binary files /dev/null and b/server/public/floris/75093389-2ac3-429a-90cf-83fe44891742.png differ diff --git a/server/public/floris/7d5a9133-93b5-4edd-9119-519f66937c66.png b/server/public/floris/7d5a9133-93b5-4edd-9119-519f66937c66.png new file mode 100644 index 0000000..b2d290f Binary files /dev/null and b/server/public/floris/7d5a9133-93b5-4edd-9119-519f66937c66.png differ diff --git a/server/public/floris/7d9ba71a-ad1b-4b6d-9596-cf4cd0a99299.png b/server/public/floris/7d9ba71a-ad1b-4b6d-9596-cf4cd0a99299.png new file mode 100644 index 0000000..57a8a5f Binary files /dev/null and b/server/public/floris/7d9ba71a-ad1b-4b6d-9596-cf4cd0a99299.png differ diff --git a/server/public/floris/7f4e6ca1-4067-4fdd-94dc-40f6057f63e3.png b/server/public/floris/7f4e6ca1-4067-4fdd-94dc-40f6057f63e3.png new file mode 100644 index 0000000..1791302 Binary files /dev/null and b/server/public/floris/7f4e6ca1-4067-4fdd-94dc-40f6057f63e3.png differ diff --git a/server/public/floris/827bca1b-ad20-4dc6-8c57-42210e47543f.png b/server/public/floris/827bca1b-ad20-4dc6-8c57-42210e47543f.png new file mode 100644 index 0000000..9698f5a Binary files /dev/null and b/server/public/floris/827bca1b-ad20-4dc6-8c57-42210e47543f.png differ diff --git a/server/public/floris/89f8b3a8-3765-48fe-9cb3-ad9daf803190.png b/server/public/floris/89f8b3a8-3765-48fe-9cb3-ad9daf803190.png new file mode 100644 index 0000000..923281f Binary files /dev/null and b/server/public/floris/89f8b3a8-3765-48fe-9cb3-ad9daf803190.png differ diff --git a/server/public/floris/90d8abed-8155-4eeb-a427-ba23798ade1b.png b/server/public/floris/90d8abed-8155-4eeb-a427-ba23798ade1b.png new file mode 100644 index 0000000..b49dce0 Binary files /dev/null and b/server/public/floris/90d8abed-8155-4eeb-a427-ba23798ade1b.png differ diff --git a/server/public/floris/935e2143-0706-46d4-9246-5e0bf92633f2.png b/server/public/floris/935e2143-0706-46d4-9246-5e0bf92633f2.png new file mode 100644 index 0000000..0e3d28c Binary files /dev/null and b/server/public/floris/935e2143-0706-46d4-9246-5e0bf92633f2.png differ diff --git a/server/public/floris/9880c167-2063-4cd5-b7cf-f777fe66c7dc.png b/server/public/floris/9880c167-2063-4cd5-b7cf-f777fe66c7dc.png new file mode 100644 index 0000000..3535b8b Binary files /dev/null and b/server/public/floris/9880c167-2063-4cd5-b7cf-f777fe66c7dc.png differ diff --git a/server/public/floris/9f4c97bb-5283-48b1-b63a-0edf4dd6719b.png b/server/public/floris/9f4c97bb-5283-48b1-b63a-0edf4dd6719b.png new file mode 100644 index 0000000..4f85b5e Binary files /dev/null and b/server/public/floris/9f4c97bb-5283-48b1-b63a-0edf4dd6719b.png differ diff --git a/server/public/floris/a570d3f5-8211-4f45-b41a-813cddc0ae75.png b/server/public/floris/a570d3f5-8211-4f45-b41a-813cddc0ae75.png new file mode 100644 index 0000000..666ac6a Binary files /dev/null and b/server/public/floris/a570d3f5-8211-4f45-b41a-813cddc0ae75.png differ diff --git a/server/public/floris/a6e854d5-c47b-4544-a4a0-5b72f647a935.png b/server/public/floris/a6e854d5-c47b-4544-a4a0-5b72f647a935.png new file mode 100644 index 0000000..666ac6a Binary files /dev/null and b/server/public/floris/a6e854d5-c47b-4544-a4a0-5b72f647a935.png differ diff --git a/server/public/floris/b79e2789-464a-4800-8dfd-57d05d61d5a1.png b/server/public/floris/b79e2789-464a-4800-8dfd-57d05d61d5a1.png new file mode 100644 index 0000000..1791302 Binary files /dev/null and b/server/public/floris/b79e2789-464a-4800-8dfd-57d05d61d5a1.png differ diff --git a/server/public/floris/bea5009e-fcd8-412d-ae18-8a8207e715e2.png b/server/public/floris/bea5009e-fcd8-412d-ae18-8a8207e715e2.png new file mode 100644 index 0000000..a08fb13 Binary files /dev/null and b/server/public/floris/bea5009e-fcd8-412d-ae18-8a8207e715e2.png differ diff --git a/server/public/floris/bee4effc-e476-455b-95e1-ff4375402fbb.png b/server/public/floris/bee4effc-e476-455b-95e1-ff4375402fbb.png new file mode 100644 index 0000000..9698f5a Binary files /dev/null and b/server/public/floris/bee4effc-e476-455b-95e1-ff4375402fbb.png differ diff --git a/server/public/floris/c4a606de-669f-45a2-b8a8-1d5f044103a4.png b/server/public/floris/c4a606de-669f-45a2-b8a8-1d5f044103a4.png new file mode 100644 index 0000000..53c3e8f Binary files /dev/null and b/server/public/floris/c4a606de-669f-45a2-b8a8-1d5f044103a4.png differ diff --git a/server/public/floris/cf3a0493-c8a8-4967-87d4-7c3016f7a887.png b/server/public/floris/cf3a0493-c8a8-4967-87d4-7c3016f7a887.png new file mode 100644 index 0000000..2574601 Binary files /dev/null and b/server/public/floris/cf3a0493-c8a8-4967-87d4-7c3016f7a887.png differ diff --git a/server/public/floris/cf9e1696-1a96-427f-82fe-2ac042fd3178.png b/server/public/floris/cf9e1696-1a96-427f-82fe-2ac042fd3178.png new file mode 100644 index 0000000..2d7a9db Binary files /dev/null and b/server/public/floris/cf9e1696-1a96-427f-82fe-2ac042fd3178.png differ diff --git a/server/public/floris/d3630984-05d1-4732-8830-c93a27e05782.png b/server/public/floris/d3630984-05d1-4732-8830-c93a27e05782.png new file mode 100644 index 0000000..3036a91 Binary files /dev/null and b/server/public/floris/d3630984-05d1-4732-8830-c93a27e05782.png differ diff --git a/server/public/floris/d7ab3f3c-2bf9-4f16-81c9-4946aadc0648.png b/server/public/floris/d7ab3f3c-2bf9-4f16-81c9-4946aadc0648.png new file mode 100644 index 0000000..39b486c Binary files /dev/null and b/server/public/floris/d7ab3f3c-2bf9-4f16-81c9-4946aadc0648.png differ diff --git a/server/public/floris/de88c5da-c7e5-4bcc-b848-8581cacbc309.png b/server/public/floris/de88c5da-c7e5-4bcc-b848-8581cacbc309.png new file mode 100644 index 0000000..44a1cf1 Binary files /dev/null and b/server/public/floris/de88c5da-c7e5-4bcc-b848-8581cacbc309.png differ diff --git a/server/public/floris/e0edd7fd-8dca-46ce-9b10-6f33e73cd1b8.png b/server/public/floris/e0edd7fd-8dca-46ce-9b10-6f33e73cd1b8.png new file mode 100644 index 0000000..4925bd5 Binary files /dev/null and b/server/public/floris/e0edd7fd-8dca-46ce-9b10-6f33e73cd1b8.png differ diff --git a/server/public/floris/e15a6bf8-e08f-426b-96b0-efe3f95cdab1.png b/server/public/floris/e15a6bf8-e08f-426b-96b0-efe3f95cdab1.png new file mode 100644 index 0000000..c1a26dd Binary files /dev/null and b/server/public/floris/e15a6bf8-e08f-426b-96b0-efe3f95cdab1.png differ diff --git a/server/public/floris/e35293fd-043f-4866-b3e9-6ff75c92eab8.png b/server/public/floris/e35293fd-043f-4866-b3e9-6ff75c92eab8.png new file mode 100644 index 0000000..9698f5a Binary files /dev/null and b/server/public/floris/e35293fd-043f-4866-b3e9-6ff75c92eab8.png differ diff --git a/server/public/floris/f0650bc4-1301-4440-be56-89a223b80018.png b/server/public/floris/f0650bc4-1301-4440-be56-89a223b80018.png new file mode 100644 index 0000000..a08fb13 Binary files /dev/null and b/server/public/floris/f0650bc4-1301-4440-be56-89a223b80018.png differ diff --git a/server/public/floris/f401df27-2e48-49aa-b455-d84a7cb025e4.png b/server/public/floris/f401df27-2e48-49aa-b455-d84a7cb025e4.png new file mode 100644 index 0000000..c2ed1f7 Binary files /dev/null and b/server/public/floris/f401df27-2e48-49aa-b455-d84a7cb025e4.png differ diff --git a/server/public/floris/fb3ec95d-ef0b-4214-92fc-60fdbff20a69.png b/server/public/floris/fb3ec95d-ef0b-4214-92fc-60fdbff20a69.png new file mode 100644 index 0000000..2063c75 Binary files /dev/null and b/server/public/floris/fb3ec95d-ef0b-4214-92fc-60fdbff20a69.png differ diff --git a/server/src/.cache.sqlite b/server/src/.cache.sqlite index 3ba360a..b9bebe0 100644 Binary files a/server/src/.cache.sqlite and b/server/src/.cache.sqlite differ