npm.io
1.2.28 • Published 2 years ago

iwish-core-frontend

Licence
ISC
Version
1.2.28
Deps
6
Size
9.7 MB
Vulns
1
Weekly
0

iwish-core

useful hooks

response of api calls are in this format :

interface IApiResponse {
    code: number;
    success: boolean;
    loading: boolean;
    message: string;
    data: any;
    errors: {},
}
enum authGuard {
    none = 0,
    client = 1,
    panel = 2,
    admin_panel = 3,
}

enum API_METHODS  {
    POST   = 'post',
    GET    = 'get',
    PUT    = 'put',
    DELETE = 'delete',
}

interface IFetch {
    url: string;
    body: {}
}

interface IFetchInputs extends IFetch {
    // method: API_METHODS;
    method: 'post' | 'get' | 'put' | 'delete';
    authGuard?: authGuard;
    header?:IHeaders;
}

interface IHeaderItem {
    header: string;
    value: string;    
}

interface IHeaders extends Array<IHeaderItem> {}

useIwishCoreAuth

  • requestOtpCode <IRequestOtpCodeProps>

  • login <ILoginProps>

  • loginOAuth <ILoginWithTokenProps>

  • register <IRegisterProps>

  • reset <IResetProps>

  • refresh <>

  • logout <>

  • getMe <>

interface IAuth {
    mobile?: string;
    authGuard: authGuard;
}

interface IRequestOtpCodeProps extends IAuth {
    mobile: string;
}

interface ILoginProps extends IAuth {
    password: string;
}

interface IRegisterProps extends IAuth {
    verification_code: string;
    password: string;
}

interface IResetProps extends IAuth {
    password: string,
    password_confirmation: string,
    verification_code: string
}

interface ILoginWithTokenProps extends Omit<IAuth, "mobile"> {
    oauth: string
}
useIwishCoreCookie
  • checkHasAuthCookie

  • getDataFromCookie

  • addDataToCookie

  • removeDataCookie

useIwishCoreFetch
  • fetch <IFetchInputs>
useIwishCoreFetchSurvey
  • getSurvey

  • getSurveys

  • createSurvey

  • updateSurvey

  • deleteSurvey

  • getSurveyAnswers

  • updateSurveyQuestions