MockService.onGet("/faq").reply(() => {
return [200, faqs];
});
export const FAQ = () => {
const classes = useStyles();
const [{ device }] = useAppStore();
const switchDeviceSize = device.isMobile ? 12 : 4;
const [currentFaqs, setCurrentFaqs] = useState<Faq[]>([]);
useEffect(() => {
(async () => {
try {
const faqs = await HttpService.get<Faq[]>("/faq");
setCurrentFaqs(faqs);
console.log(faqs);
} catch (error) {}
})();
}, []);
return (
<div>
<div className={classes.root}>
<GridContainer>
<GridRow>
<GridColumn>
<header className={classes.headerSearch}>
<GridColumn>
<div className={classes.mainHeading}>
Какую информацию вы хотите найти?
</div>
</GridColumn>
<GridColumn size={10} offset={1}>
<Input
type="text"
placeholder="Найдите всё, что требуется(онлайн-консультация,
добавление записи в медкарту...)"
fullWidth
classes={{
inputWrapper: classes.searchField,
}}
startAdornment={
<InputAdornment
position="start"
classes={{ root: classes.searchImg }}
>
<Search></Search>
</InputAdornment>
}
/>
</GridColumn>
</header>
</GridColumn>
</GridRow>
<GridRow>
{currentFaqs.map((card) => {
return (
<GridColumn size={switchDeviceSize}>
<Link to={`/faq/${card.id}`}>
<div className={classes.blockCard} key={card.id}>
<div className={classes.boxTitle}>
<p className={classes.titleSection}>{card.title}</p>
<p className={classes.textSection}>{card.content}</p>
</div>
</div>
</Link>
</GridColumn>
);
})}
</GridRow>
</GridContainer>
</div>
</div>
);
};
type Params = {
id: string;
}
MockService.onGet(/faq\/\d+$/).reply(() => {
return [200, faqs[0]]
});
export const FaqCards = () => {
const { id } = useParams<Params>();
console.log(id)
const [currentFaqs, setCurrentFaqs] = useState<Faq[] | null>();
const classes = useStyles();
useEffect(() => {
(async () => {
try {
const faqsId = await HttpService.get<Faq[]>(`/faqs/${id}`);
setCurrentFaqs(faqsId);
} catch (error) {}
})();
},[id]);
if(currentFaqs === null) return null;
else {
return (
<div className={classes.root}>
<GridContainer>
<GridRow>
<GridColumn>
<div className={classes.cards}key={id}>
<div className={classes.blockTitle}>
<p className={classes.title}>{faqs.title}</p>
<p className={classes.content}>{faqs.content}</p>
</div>
</div>
</GridColumn>
</GridRow>
</GridContainer>
</div>
);
};
};
const faqsId = await HttpService.get<Faq[]>(`/faqs/${id}`);
setCurrentFaqs(faqsId);
MockService.onGet(/faq\/\d+$/).reply(() => {
return [200, faqs[0]]
});
export const FaqCards = () => {
const { id } = useParams<Params>();
console.log(id)
const [currentFaqs, setCurrentFaqs] = useState<Faq[] | null>();
const classes = useStyles();
useEffect(() => {
(async () => {
try {
const faqsId = await HttpService.get<Faq[]>(`/faqs/${id}`);
setCurrentFaqs(faqsId);
} catch (error) {}
})();
},[id]);
if(currentFaqs === null) return null;
else {
return (
<div className={classes.root}>
<GridContainer>
<GridRow>
<GridColumn>
<div className={classes.cards}key={id}>
<div className={classes.blockTitle}>
<p className={classes.title}>{faqs.title}</p>
<p className={classes.content}>{faqs.content}</p>
</div>
</div>
</GridColumn>
</GridRow>
</GridContainer>
</div>
);
};
};
MockService.onGet(/faqs\/\d+$/).reply(() => {
return [200, faqs[0]]
});
faqs[0]
`/faqs/${id}`
и на основе этого получать нужный.