Set redux state whenever website data is fetched
parent
fe861795bc
commit
9efd3eaa6a
|
@ -1,4 +1,6 @@
|
|||
import React, { useState } from 'react';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { useDispatch } from 'react-redux';
|
||||
import { setWebsiteCreated } from 'redux/actions/websites';
|
||||
import { FormattedMessage } from 'react-intl';
|
||||
import classNames from 'classnames';
|
||||
import WebsiteChart from 'components/metrics/WebsiteChart';
|
||||
|
@ -34,6 +36,7 @@ const views = {
|
|||
};
|
||||
|
||||
export default function WebsiteDetails({ websiteId }) {
|
||||
const dispatch = useDispatch();
|
||||
const shareToken = useShareToken();
|
||||
const { data } = useFetch(`/api/website/${websiteId}`, {
|
||||
headers: { [TOKEN_HEADER]: shareToken?.token },
|
||||
|
@ -46,6 +49,10 @@ export default function WebsiteDetails({ websiteId }) {
|
|||
query: { view },
|
||||
} = usePageQuery();
|
||||
|
||||
useEffect(() => {
|
||||
if (data) dispatch(setWebsiteCreated(websiteId, data.created_at));
|
||||
}, [data]);
|
||||
|
||||
const BackButton = () => (
|
||||
<div key="back-button" className={styles.backButton}>
|
||||
<Link key="back-button" href={resolve({ view: undefined })} icon={<Arrow />} size="small">
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
import React, { useState } from 'react';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { useDispatch } from 'react-redux';
|
||||
import { setWebsiteCreated } from 'redux/actions/websites';
|
||||
import { FormattedMessage } from 'react-intl';
|
||||
import Link from 'components/common/Link';
|
||||
import WebsiteChart from 'components/metrics/WebsiteChart';
|
||||
|
@ -11,9 +13,14 @@ import Chart from 'assets/chart-bar.svg';
|
|||
import styles from './WebsiteList.module.css';
|
||||
|
||||
export default function WebsiteList({ userId }) {
|
||||
const dispatch = useDispatch();
|
||||
const { data } = useFetch('/api/websites', { params: { user_id: userId } });
|
||||
const [hideCharts, setHideCharts] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (data) data.map(i => dispatch(setWebsiteCreated(i.website_id, i.created_at)));
|
||||
}, [data]);
|
||||
|
||||
if (!data) {
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue