add current user location review
This commit is contained in:
parent
3980f11f18
commit
96185ab95a
@ -13,6 +13,7 @@ const GET_LOCATION_TAGS_URI = `${BASE_URL}/location/tags`
|
|||||||
const GET_IMAGES_BY_LOCATION_URI = `${BASE_URL}/images/location`
|
const GET_IMAGES_BY_LOCATION_URI = `${BASE_URL}/images/location`
|
||||||
|
|
||||||
const POST_REVIEW_LOCATION_URI = `${BASE_URL}/review/location`
|
const POST_REVIEW_LOCATION_URI = `${BASE_URL}/review/location`
|
||||||
|
const GET_CURRENT_USER_REVIEW_LOCATION_URI = `${BASE_URL}/user/review/location`
|
||||||
|
|
||||||
export {
|
export {
|
||||||
BASE_URL,
|
BASE_URL,
|
||||||
@ -25,5 +26,6 @@ export {
|
|||||||
GET_LOCATION_URI,
|
GET_LOCATION_URI,
|
||||||
GET_LOCATION_TAGS_URI,
|
GET_LOCATION_TAGS_URI,
|
||||||
GET_IMAGES_BY_LOCATION_URI,
|
GET_IMAGES_BY_LOCATION_URI,
|
||||||
POST_REVIEW_LOCATION_URI
|
POST_REVIEW_LOCATION_URI,
|
||||||
|
GET_CURRENT_USER_REVIEW_LOCATION_URI,
|
||||||
}
|
}
|
@ -11,7 +11,7 @@ import {
|
|||||||
CurrentUserLocationReviews,
|
CurrentUserLocationReviews,
|
||||||
} from './types';
|
} from './types';
|
||||||
import { handleAxiosError, useAutosizeTextArea } from '../../utils';
|
import { handleAxiosError, useAutosizeTextArea } from '../../utils';
|
||||||
import { getImagesByLocationService, getLocationService, postReviewLocation } from "../../services";
|
import { getCurrentUserLocationReviewService, getImagesByLocationService, getLocationService, postReviewLocation } from "../../services";
|
||||||
import { DefaultSeparator, SeparatorWithAnchor, CustomInterweave, SpinnerLoading } from '../../components';
|
import { DefaultSeparator, SeparatorWithAnchor, CustomInterweave, SpinnerLoading } from '../../components';
|
||||||
import { useSelector } from 'react-redux';
|
import { useSelector } from 'react-redux';
|
||||||
import { UserRootState } from '../../store/type';
|
import { UserRootState } from '../../store/type';
|
||||||
@ -80,6 +80,16 @@ function LocationDetail() {
|
|||||||
setIsLoading(false)
|
setIsLoading(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function getCurrentUserLocationReview() {
|
||||||
|
try {
|
||||||
|
const res = await getCurrentUserLocationReviewService(Number(id))
|
||||||
|
setCurrentUserReview(res.data)
|
||||||
|
setPageState({ ...pageState, enable_post: false})
|
||||||
|
} catch (error) {
|
||||||
|
alert(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function handleTextAreaChange(e: ChangeEvent<HTMLTextAreaElement>): void {
|
function handleTextAreaChange(e: ChangeEvent<HTMLTextAreaElement>): void {
|
||||||
const val = e.target as HTMLTextAreaElement;
|
const val = e.target as HTMLTextAreaElement;
|
||||||
|
|
||||||
@ -168,6 +178,7 @@ function LocationDetail() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
getCurrentUserLocationReview()
|
||||||
getLocationDetail()
|
getLocationDetail()
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import {
|
|||||||
} from "./locations";
|
} from "./locations";
|
||||||
import { getImagesByLocationService } from "./images"
|
import { getImagesByLocationService } from "./images"
|
||||||
import { createAccountService, loginService, logoutService } from "./auth";
|
import { createAccountService, loginService, logoutService } from "./auth";
|
||||||
import { postReviewLocation } from "./review";
|
import { postReviewLocation, getCurrentUserLocationReviewService } from "./review";
|
||||||
|
|
||||||
export {
|
export {
|
||||||
createAccountService,
|
createAccountService,
|
||||||
@ -21,5 +21,6 @@ export {
|
|||||||
getLocationTagsService,
|
getLocationTagsService,
|
||||||
getImagesByLocationService,
|
getImagesByLocationService,
|
||||||
|
|
||||||
postReviewLocation
|
postReviewLocation,
|
||||||
|
getCurrentUserLocationReviewService,
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
import { AxiosError } from "axios"
|
import { AxiosError } from "axios"
|
||||||
import { client } from "./config";
|
import { client } from "./config";
|
||||||
import { POST_REVIEW_LOCATION_URI } from "../constants/api";
|
import { GET_CURRENT_USER_REVIEW_LOCATION_URI, POST_REVIEW_LOCATION_URI } from "../constants/api";
|
||||||
|
|
||||||
const initialState: IEmptyResponseState = {
|
const initialState: IEmptyResponseState = {
|
||||||
data: null,
|
data: null,
|
||||||
@ -29,6 +29,19 @@ async function postReviewLocation(req: postReviewLocationReq) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
async function getCurrentUserLocationReviewService(location_id: number) {
|
||||||
postReviewLocation
|
const newState = { ...initialState };
|
||||||
|
try {
|
||||||
|
const response = await client({ method: 'GET', url: `${GET_CURRENT_USER_REVIEW_LOCATION_URI}/${location_id}`, withCredentials: true})
|
||||||
|
newState.data = response.data
|
||||||
|
newState.error = null
|
||||||
|
return newState
|
||||||
|
} catch (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
postReviewLocation,
|
||||||
|
getCurrentUserLocationReviewService,
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user