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