fix and refactor types
This commit is contained in:
parent
cdb3fa2955
commit
4bc60a6dd3
@ -1,7 +1,8 @@
|
|||||||
|
import { TargetedEvent } from "preact/compat";
|
||||||
import { useEffect, useState } from "preact/hooks";
|
import { useEffect, useState } from "preact/hooks";
|
||||||
import { getListTopLocationsService } from "../../services";
|
import { getListTopLocationsService } from "../../services";
|
||||||
import { DefaultSeparator } from "../../components";
|
import { DefaultSeparator } from "../../components";
|
||||||
import { TargetedEvent } from "preact/compat";
|
import { NullValueRes } from "../../types/common";
|
||||||
import './style.css';
|
import './style.css';
|
||||||
|
|
||||||
interface TopLocation {
|
interface TopLocation {
|
||||||
|
@ -10,6 +10,7 @@ import {
|
|||||||
emptyLocationResponse,
|
emptyLocationResponse,
|
||||||
CurrentUserLocationReviews,
|
CurrentUserLocationReviews,
|
||||||
} from './types';
|
} from './types';
|
||||||
|
import { AxiosError } from 'axios';
|
||||||
import { handleAxiosError, useAutosizeTextArea } from '../../utils';
|
import { handleAxiosError, useAutosizeTextArea } from '../../utils';
|
||||||
import { getCurrentUserLocationReviewService, 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';
|
||||||
@ -17,7 +18,7 @@ import { useSelector } from 'react-redux';
|
|||||||
import { UserRootState } from '../../store/type';
|
import { UserRootState } from '../../store/type';
|
||||||
import { DEFAULT_AVATAR_IMG } from '../../constants/default';
|
import { DEFAULT_AVATAR_IMG } from '../../constants/default';
|
||||||
import './index.css';
|
import './index.css';
|
||||||
import { AxiosError } from 'axios';
|
import { IHttpResponse } from '../../types/common';
|
||||||
|
|
||||||
const SORT_TYPE = [
|
const SORT_TYPE = [
|
||||||
'highest rated',
|
'highest rated',
|
||||||
@ -88,9 +89,8 @@ function LocationDetail() {
|
|||||||
setCurrentUserReview(res.data)
|
setCurrentUserReview(res.data)
|
||||||
setPageState({ ...pageState, enable_post: false})
|
setPageState({ ...pageState, enable_post: false})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error)
|
|
||||||
let err = error as IHttpResponse;
|
let err = error as IHttpResponse;
|
||||||
if(err.status == 404) {
|
if(err.status == 404 || err.status == 401 ) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
alert(err.error.response.data.message)
|
alert(err.error.response.data.message)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { AxiosError } from "axios";
|
import { AxiosError } from "axios";
|
||||||
import { LOGIN_URI, SIGNUP_URI } from "../constants/api";
|
import { LOGIN_URI, SIGNUP_URI } from "../constants/api";
|
||||||
import { client } from "./config";
|
import { client } from "./config";
|
||||||
|
import { IHttpResponse } from "../types/common";
|
||||||
|
|
||||||
const initialState: IHttpResponse = {
|
const initialState: IHttpResponse = {
|
||||||
data: null,
|
data: null,
|
||||||
@ -28,7 +29,7 @@ async function createAccountService({ username, password }: IAuthentication) {
|
|||||||
async function loginService({ username, password }: IAuthentication) {
|
async function loginService({ username, password }: IAuthentication) {
|
||||||
const newState = { ...initialState };
|
const newState = { ...initialState };
|
||||||
try {
|
try {
|
||||||
const response = await client({ method: 'POST', url: LOGIN_URI, data: { username, password }, withCredentials: true })
|
const response = await client({ method: 'POST', url: LOGIN_URI, data: { username, password } })
|
||||||
newState.data = response.data
|
newState.data = response.data
|
||||||
newState.error = null
|
newState.error = null
|
||||||
return newState
|
return newState
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { IUser } from "../features/auth/authSlice/type";
|
import { User } from "../domains";
|
||||||
import { RootState } from "./config";
|
import { RootState } from "./config";
|
||||||
|
|
||||||
export interface UserRootState extends RootState {
|
export interface UserRootState extends RootState {
|
||||||
auth: IUser
|
auth: User
|
||||||
}
|
}
|
@ -1,14 +1,34 @@
|
|||||||
type BaseNullValueRes = { Valid: boolean };
|
import { Province, Regency, Region } from "../domains";
|
||||||
type NullValueRes<Key extends string, _> = BaseNullValueRes & Record<Key, string | number>
|
|
||||||
|
|
||||||
interface GetRequestPagination {
|
type BaseNullValueRes = { Valid: boolean };
|
||||||
|
export type NullValueRes<Key extends string, _> = BaseNullValueRes & Record<Key, string | number>
|
||||||
|
|
||||||
|
export interface GetRequestPagination {
|
||||||
page: number,
|
page: number,
|
||||||
page_size: number,
|
page_size: number,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IHttpResponse {
|
||||||
interface IHttpResponse {
|
|
||||||
data: any,
|
data: any,
|
||||||
error: any,
|
error: any,
|
||||||
status?: number,
|
status?: number,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export interface IDropdownInputProps {
|
||||||
|
label: string,
|
||||||
|
value: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IndonesiaRegionsInfo {
|
||||||
|
regions?: Array<Region>,
|
||||||
|
provinces?: Array<Province>,
|
||||||
|
regencies?: Array<Regency>,
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum LocationType {
|
||||||
|
Beach = "beach",
|
||||||
|
AmusementPark = "amusement park",
|
||||||
|
Culinary = "culinary",
|
||||||
|
HikingCamping = "hiking / camping",
|
||||||
|
Other = "other"
|
||||||
|
}
|
||||||
|
@ -2,4 +2,8 @@ import { AxiosError } from "axios";
|
|||||||
|
|
||||||
export function handleAxiosError(error: AxiosError) {
|
export function handleAxiosError(error: AxiosError) {
|
||||||
return error.response?.data
|
return error.response?.data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function enumKeys<O extends object, K extends keyof O = keyof O>(obj: O): K[] {
|
||||||
|
return Object.keys(obj).filter(k => Number.isNaN(+k)) as K[];
|
||||||
|
}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import useAutosizeTextArea from "./useAutosizeTextArea";
|
import useAutosizeTextArea from "./useAutosizeTextArea";
|
||||||
import { handleAxiosError } from "./common";
|
import { handleAxiosError, enumKeys } from "./common";
|
||||||
|
|
||||||
export {
|
export {
|
||||||
useAutosizeTextArea,
|
useAutosizeTextArea,
|
||||||
handleAxiosError
|
handleAxiosError,
|
||||||
|
enumKeys,
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user