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 POST_REVIEW_LOCATION_URI = `${BASE_URL}/review/location`
|
||||
const GET_CURRENT_USER_REVIEW_LOCATION_URI = `${BASE_URL}/user/review/location`
|
||||
|
||||
export {
|
||||
BASE_URL,
|
||||
@ -25,5 +26,6 @@ export {
|
||||
GET_LOCATION_URI,
|
||||
GET_LOCATION_TAGS_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,
|
||||
} from './types';
|
||||
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 { useSelector } from 'react-redux';
|
||||
import { UserRootState } from '../../store/type';
|
||||
@ -80,6 +80,16 @@ function LocationDetail() {
|
||||
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 {
|
||||
const val = e.target as HTMLTextAreaElement;
|
||||
|
||||
@ -168,6 +178,7 @@ function LocationDetail() {
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
getCurrentUserLocationReview()
|
||||
getLocationDetail()
|
||||
}, [])
|
||||
|
||||
|
@ -7,7 +7,7 @@ import {
|
||||
} from "./locations";
|
||||
import { getImagesByLocationService } from "./images"
|
||||
import { createAccountService, loginService, logoutService } from "./auth";
|
||||
import { postReviewLocation } from "./review";
|
||||
import { postReviewLocation, getCurrentUserLocationReviewService } from "./review";
|
||||
|
||||
export {
|
||||
createAccountService,
|
||||
@ -21,5 +21,6 @@ export {
|
||||
getLocationTagsService,
|
||||
getImagesByLocationService,
|
||||
|
||||
postReviewLocation
|
||||
postReviewLocation,
|
||||
getCurrentUserLocationReviewService,
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
import { AxiosError } from "axios"
|
||||
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 = {
|
||||
data: null,
|
||||
@ -29,6 +29,19 @@ async function postReviewLocation(req: postReviewLocationReq) {
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
postReviewLocation
|
||||
async function getCurrentUserLocationReviewService(location_id: number) {
|
||||
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