Ensured domain is passed when loading detail for a short URL on a specific domain

This commit is contained in:
Alejandro Celaya 2020-02-08 09:38:19 +01:00
parent 707c9f4ce6
commit 170e427530
2 changed files with 9 additions and 9 deletions

View file

@ -33,8 +33,8 @@ const ShortUrlVisits = (
}; };
state = { startDate: undefined, endDate: undefined }; state = { startDate: undefined, endDate: undefined };
loadVisits = () => { loadVisits = (loadDetail = false) => {
const { match: { params }, location: { search }, getShortUrlVisits } = this.props; const { match: { params }, location: { search }, getShortUrlVisits, getShortUrlDetail } = this.props;
const { shortCode } = params; const { shortCode } = params;
const dates = mapObjIndexed(formatDate(), this.state); const dates = mapObjIndexed(formatDate(), this.state);
const { startDate, endDate } = dates; const { startDate, endDate } = dates;
@ -44,15 +44,15 @@ const ShortUrlVisits = (
// While the "page" is loaded, use the timestamp + filtering dates as memoization IDs for stats calculations // While the "page" is loaded, use the timestamp + filtering dates as memoization IDs for stats calculations
this.memoizationId = `${this.timeWhenMounted}_${shortCode}_${startDate}_${endDate}`; this.memoizationId = `${this.timeWhenMounted}_${shortCode}_${startDate}_${endDate}`;
getShortUrlVisits(shortCode, { startDate, endDate, domain }); getShortUrlVisits(shortCode, { startDate, endDate, domain });
if (loadDetail) {
getShortUrlDetail(shortCode, domain);
}
}; };
componentDidMount() { componentDidMount() {
const { match: { params }, getShortUrlDetail } = this.props;
const { shortCode } = params;
this.timeWhenMounted = new Date().getTime(); this.timeWhenMounted = new Date().getTime();
this.loadVisits(); this.loadVisits(true);
getShortUrlDetail(shortCode);
} }
componentWillUnmount() { componentWillUnmount() {

View file

@ -26,13 +26,13 @@ export default handleActions({
[GET_SHORT_URL_DETAIL]: (state, { shortUrl }) => ({ shortUrl, loading: false, error: false }), [GET_SHORT_URL_DETAIL]: (state, { shortUrl }) => ({ shortUrl, loading: false, error: false }),
}, initialState); }, initialState);
export const getShortUrlDetail = (buildShlinkApiClient) => (shortCode) => async (dispatch, getState) => { export const getShortUrlDetail = (buildShlinkApiClient) => (shortCode, domain) => async (dispatch, getState) => {
dispatch({ type: GET_SHORT_URL_DETAIL_START }); dispatch({ type: GET_SHORT_URL_DETAIL_START });
const { getShortUrl } = await buildShlinkApiClient(getState); const { getShortUrl } = await buildShlinkApiClient(getState);
try { try {
const shortUrl = await getShortUrl(shortCode); const shortUrl = await getShortUrl(shortCode, domain);
dispatch({ shortUrl, type: GET_SHORT_URL_DETAIL }); dispatch({ shortUrl, type: GET_SHORT_URL_DETAIL });
} catch (e) { } catch (e) {