This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* @HINT: NPM package for rendering colored text on the command-line (or standard output) */ | |
const chalk = require('chalk'); | |
/* @HINT: This uses the `chalk` NPM package to setup colors for failed test assertions as well as passed test assertions */ | |
const failStatus = chalk.red; | |
const passStatus = chalk.green; | |
/* @HINT: A helper function using the status of an assertion to color text sent to the command-line (or standard output) */ | |
const standardOutputPrettify = (isOk, statusText, prefix = "") => { | |
return isOk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* object.watch polyfill | |
* | |
* 2012-04-03 | |
* | |
* By Eli Grey, http://eligrey.com | |
* Public Domain. | |
* NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useContext, useMemo } from "react"; | |
import type { UseQueryResult } from "react-query"; | |
type ReactQueryFetchStatus = "idle" | "loading" | "error" | "success"; | |
export type UseQueryPackedUnion = "status" | "data"; | |
/* | |
type ReactQueryFetchHook<F extends Array<unknown>, Q = any, P = any> = (...hookArguments: [...F, P?]) => UseQueryResult<Q> | Pick<UseQueryResult<Q>, UseQueryPackedUnion> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Yup from "yup"; | |
import type { InferType } from "yup"; | |
const UserSchema = Yup.object({ | |
name: Yup.string().required(), | |
email: Yup.string().email().required(), | |
fullname: Yup.string().required(), | |
title: Yup.string().required(), | |
gender: Yup.string().required().default("male"), | |
rating: Yup.number().min(1).max(10).required(), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useRef, useState, useEffect, useCallback, Children, isValidElement, cloneElement } from "react"; | |
import Router from "next/router"; | |
import { useIsFirstRender } from "react-busser"; | |
export type FormStepComponentProps = { | |
currentStep: string | number, | |
stepsTotal: number, | |
onStepChange: (data: Record<string, any>, disableFormSubmission?: boolean, shouldNavigate?: boolean) => Promise<boolean>, | |
onFormChange: (htmlForm: HTMLFormElement, htmlFormValue: { [key: string]: any }) => number; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios, { AxiosError, AxiosResponse, AxiosRequestConfig, AxiosHeaders } from "axios"; | |
import { API, authRefreshTokenStorageKeyName, authTokenStorageKeyName, userVerifyTokenStorageKeyName } from "@/constants"; | |
import { handleLogout, isCORSViolation } from "./utils"; | |
export type { AxiosError }; | |
export interface OptionsArgs<BodyType, ParamType = any> { | |
body?: BodyType; | |
headers?: { [key: string]: any }; | |
params?: ParamType, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useQueryClient } from "@tanstack/react-query"; | |
export function useReactQueryCache<D, E>(queryKey: unknown[] = []) { | |
const queryClient = useQueryClient(); | |
const queryCache = queryClient.getQueryCache(); | |
return queryCache.find<D, E>(queryKey); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useRouter } from "next/router"; | |
import { useRef } from "react"; | |
export const useNexJSPreviousRoute = () => { | |
const router = useRouter(); | |
const ref = useRef<string | null>(null); | |
router.events?.on("routeChangeStart", () => { | |
ref.current = router.asPath; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useRouter } from "next/router"; | |
import { useState, useEffect } from "react"; | |
export const useNextJSUnsavedChangesLock = ({ | |
promptText = "You have unsaved changes - are you sure you wish to leave this page?", | |
useBrowserPrompt = true, | |
unsavedChangesStatus = false | |
}: { promptText: string, useBrowserPrompt?: boolean, unsavedChangesStatus?: boolean }) => { | |
const router = useRouter(); | |
router.beforePopState((state) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { lazy } from "react"; | |
import type { JSX } from "react"; | |
/** | |
* lazyWithRetry: | |
* | |
* @param {() => (() => JSX.Element)} componentImport | |
* @returns {() => JSX.Element} | |
* | |
* @see https://gist.github.com/raphael-leger/4d703dea6c845788ff9eb36142374bdb#file-lazywithretry-js |
NewerOlder