complete pages and response
This commit is contained in:
parent
fb64dfa1b7
commit
cef3474b43
@ -32,7 +32,12 @@ const LaptopPredictPage = () => {
|
|||||||
|
|
||||||
const handleGetPredict = async (event: FormEvent) => {
|
const handleGetPredict = async (event: FormEvent) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
console.log(request);
|
if (response.predicted_price) {
|
||||||
|
setResponse({
|
||||||
|
predicted_price: undefined,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
const newResponse = await apiLaptop.predictPrice(request);
|
const newResponse = await apiLaptop.predictPrice(request);
|
||||||
setResponse(newResponse);
|
setResponse(newResponse);
|
||||||
};
|
};
|
||||||
|
@ -31,7 +31,12 @@ const TVPredictPage = () => {
|
|||||||
|
|
||||||
const handleGetPredict = async (event: FormEvent) => {
|
const handleGetPredict = async (event: FormEvent) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
console.log(request);
|
if (response.predicted_price) {
|
||||||
|
setResponse({
|
||||||
|
predicted_price: undefined,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
const newResponse = await apiTV.predictPrice(request);
|
const newResponse = await apiTV.predictPrice(request);
|
||||||
setResponse(newResponse);
|
setResponse(newResponse);
|
||||||
};
|
};
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { PredictResponseType } from '@/shared/types/predict';
|
import { PredictResponseType } from '@/shared/types/predict';
|
||||||
import { FormEvent } from 'react';
|
import { FormEvent, useMemo } from 'react';
|
||||||
import classes from './styles.module.scss';
|
import classes from './styles.module.scss';
|
||||||
import { Button } from '@/shared/components/button';
|
import { Button } from '@/shared/components/button';
|
||||||
import { Selector } from '@/shared/components/selector';
|
import { Selector } from '@/shared/components/selector';
|
||||||
@ -22,8 +22,14 @@ const Form = <T extends Record<string, string[] | number[]>>({
|
|||||||
? (Object.keys(selectorsData) as Array<keyof T>)
|
? (Object.keys(selectorsData) as Array<keyof T>)
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
|
const buttonLabel = useMemo(
|
||||||
|
() => (response.predicted_price ? 'Back to build' : 'Submit'),
|
||||||
|
[response.predicted_price],
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form className={classes.form}>
|
<form className={classes.form}>
|
||||||
|
{!response.predicted_price ? (
|
||||||
<div className={classes.selectorList}>
|
<div className={classes.selectorList}>
|
||||||
{fields.map((field) => (
|
{fields.map((field) => (
|
||||||
<Expander key={field as string} title={field as string}>
|
<Expander key={field as string} title={field as string}>
|
||||||
@ -35,13 +41,16 @@ const Form = <T extends Record<string, string[] | number[]>>({
|
|||||||
</Expander>
|
</Expander>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
<div className={classes.divider} />
|
) : (
|
||||||
<Button onClick={(e: FormEvent) => handleGetPredict(e)}>Submit</Button>
|
<div className={classes.response}>
|
||||||
{response.predicted_price !== undefined && (
|
<h3 className={classes.title}>Estimated price:</h3>
|
||||||
<span style={{ color: 'white' }}>
|
<p className={classes.price}>{response.predicted_price} руб</p>
|
||||||
Ответ: {response.predicted_price}
|
</div>
|
||||||
</span>
|
|
||||||
)}
|
)}
|
||||||
|
<div className={classes.divider} />
|
||||||
|
<Button onClick={(e: FormEvent) => handleGetPredict(e)}>
|
||||||
|
{buttonLabel}
|
||||||
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
@use '../../shared/assets/styles/adaptive' as adaptive;
|
@use '@shared/assets/styles/adaptive' as adaptive;
|
||||||
|
@use '@shared/assets/styles/fonts' as fonts;
|
||||||
|
|
||||||
.form {
|
.form {
|
||||||
display: flex;
|
display: flex;
|
||||||
@ -15,6 +16,25 @@
|
|||||||
gap: 8px;
|
gap: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.response {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
padding: 16px;
|
||||||
|
gap: 16px;
|
||||||
|
background-color: var(--primary-white);
|
||||||
|
border-radius: 16px;
|
||||||
|
|
||||||
|
.title {
|
||||||
|
margin: 0;
|
||||||
|
@include fonts.urbanist-font(28px, 600);
|
||||||
|
}
|
||||||
|
|
||||||
|
.price {
|
||||||
|
margin: 0;
|
||||||
|
@include fonts.urbanist-font(20px, 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.divider {
|
.divider {
|
||||||
height: 4px;
|
height: 4px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
Loading…
Reference in New Issue
Block a user