Skip to content

Instantly share code, notes, and snippets.

// Interceptor
const setupAxiosInterceptors = (onUnauthenticated: () => void) => {
const onRequestSuccess = (config: AxiosRequestConfig) => {
console.log("request success", config);
const token = Storage.local.get("auth");
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}
return config;
export const authLoginEffects = (data: AuthLoginFormData) => (
dispatch: ThunkDispatch<{}, {}, AnyAction>
) => {
AuthService.login(data)
.then((data) => {
dispatch(authLoginSuccess(data));
Storage.local.set("auth", data);
dispatch(push("/user"));
})
.catch((_) => {
@whisher
whisher / gist:c8e0453a5fa76b5d6d952919c77ef0c4
Last active January 28, 2023 06:07
reactjs typescript useForm - a simple custom hook to manage form in react
Credit to
https://medium.com/javascript-in-plain-english/react-controlled-forms-with-hooks-538762aab935
import React, { ChangeEvent, FormEvent, useReducer } from "react";
const useForm = (initialState: any) => {
const reducer = (
state: typeof initialState,
payload: { field: string; value: string }
) => {
@Injectable()
export class CategoriesGuard implements CanActivate {
constructor(private store: Store<fromStore.CategoriesState>) {}
canActivate(): Observable<boolean> {
return this.checkStore().pipe(
switchMap(() => of(true)),
catchError(() => of(false))
);
}
import React from "react";
export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
onClick: () => void;
}
const Button: React.FC<ButtonProps> = ({
children,
...buttonProps
}) => {
return (
Module
// Core
import { NgModule, Optional, SkipSelf } from '@angular/core';
// Big.js
import Big from 'big.js/big.mjs';
import { BigjsService } from './bigjs.service';
@NgModule({
getPendingOrders(): Observable<MatrixPendingOrders[]> {
return this.accountFacade.account$.pipe(
switchMap(account => {
let id: any = '';
if (account) {
id = account.auth.id;
}
return this.service.getPendingOrders(id);
}),
map((data: PendingOrdersDto) => data.orders),
let starterChanges$ = of(null);
const starter = this.frm.get('starter');
if (starter) {
starterChanges$ = starter.valueChanges;
}
let spreadChanges$ = of(null);
const spread = this.frm.get('spread');
if (spread) {
spreadChanges$ = spread.valueChanges;
}
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="logo192.png"/><link rel="manifest" href="/manifest.json"/><link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"/><title>React App</title><link href="/static/css/main.a38a0264.chunk.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>!function(p){function e(e){for(var r,t,n=e[0],o=e[1],u=e[2],l=0,a=[];l<n.length;l++)t=n[l],Object.prototype.hasOwnProperty.call(i,t)&&i[t]&&a.push(i[t][0]),i[t]=0;for(r in o)Object.prototype.hasOwnProperty.call(o,r)&&(p[r]=o[r]);for(s&&s(e);a.length;)a.shift()();return c.push.apply(c,u||[]),f()}function f(){for(var e,r=0;r<c.length;r++){for(var t=c[r],n=!0,
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="logo192.png"/><link rel="manifest" href="/manifest.json"/><link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"/><title>React App</title><link href="/static/css/main.a38a0264.chunk.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>!function(p){function e(e){for(var r,t,n=e[0],o=e[1],u=e[2],l=0,a=[];l<n.length;l++)t=n[l],Object.prototype.hasOwnProperty.call(i,t)&&i[t]&&a.push(i[t][0]),i[t]=0;for(r in o)Object.prototype.hasOwnProperty.call(o,r)&&(p[r]=o[r]);for(s&&s(e);a.length;)a.shift()();return c.push.apply(c,u||[]),f()}function f(){for(var e,r=0;r<c.length;r++){for(var t=c[r],n=!0,