add current user location review

This commit is contained in:
NCanggoro 2023-09-27 22:46:14 +07:00
parent 3980f11f18
commit 96185ab95a
4 changed files with 43 additions and 16 deletions

View File

@ -1,18 +1,19 @@
const BASE_URL = "http://localhost:8888" const BASE_URL = "http://localhost:8888"
const SIGNUP_URI = `${BASE_URL}/user/signup` const SIGNUP_URI = `${BASE_URL}/user/signup`
const LOGIN_URI = `${BASE_URL}/user/login` const LOGIN_URI = `${BASE_URL}/user/login`
const LOGOUT_URI = `${BASE_URL}/user/logout` const LOGOUT_URI = `${BASE_URL}/user/logout`
const GET_LIST_LOCATIONS_URI = `${BASE_URL}/locations`; const GET_LIST_LOCATIONS_URI = `${BASE_URL}/locations`;
const GET_LIST_TOP_LOCATIONS = `${BASE_URL}/locations/top-ratings` const GET_LIST_TOP_LOCATIONS = `${BASE_URL}/locations/top-ratings`
const GET_LIST_RECENT_LOCATIONS_RATING_URI = `${BASE_URL}/locations/recent` const GET_LIST_RECENT_LOCATIONS_RATING_URI = `${BASE_URL}/locations/recent`
const GET_LOCATION_URI = `${BASE_URL}/location`; const GET_LOCATION_URI = `${BASE_URL}/location`;
const GET_LOCATION_TAGS_URI = `${BASE_URL}/location/tags` 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,
} }

View File

@ -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()
}, []) }, [])

View File

@ -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,
} }

View File

@ -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,
} }