Skip to content

Instantly share code, notes, and snippets.

@vinodsobale
vinodsobale / withAuth.js
Created December 13, 2018 06:06
HOC wrapper to redirect and provide token to all pages that need to be protected
import React from "react";
import Router from "next/router";
import universalCookie from "cookie";
import authApi from "../api/authApi";
import { redirectToLogin } from "../lib/utils";
export default function withAuth(AuthComponent) {
return class Authenticated extends React.Component {
static async getInitialProps(ctx) {
@vinodsobale
vinodsobale / geolocation.js
Created December 11, 2018 05:15
geolocation
getLocation() {
this.setState((prevState, props) => {
return {
fetchingLocation: true
};
});
getGeoLocation()
.then(position => {
this.setState((prevState, props) => {
return {
{"name":"New_Segment","status":"CREATE","owner":"Vinod Sobale","type":"country","createDate":1544092433000,"expression":{"left":{"left":"country","operator":"equals","right":"KW","datatype":""},"operator":"and","right":{"left":{"left":"carrier","operator":"equals","right":"12","datatype":""},"operator":null,"right":null}}}
{
"name": "Vinod_New_Segment_1",
"status": "CREATE",
"owner": "Vinod Sobale",
"type": "country",
"createDate": 1538039745070,
"expression": {
"left": {
"left": "country",
"operator": "equals",
@vinodsobale
vinodsobale / Header.js
Created July 9, 2018 04:55
Header carrier integration code
import React from 'react';
import { connect } from 'react-redux';
import { NavLink, Link } from 'react-router-dom';
import { bindActionCreators, compose } from 'redux';
import { get as _get, pick as _pick } from 'lodash';
import Cookie from 'universal-cookie';
import ReactModal from 'react-modal';
import { translate } from 'react-i18next';
import createHistory from 'history/createBrowserHistory';
<ReactModal
isOpen={reactModal}
overlayClassName="c-socloginoverlay"
className="c-soclogin"
shouldCloseOnOverlayClick
onRequestClose={() => this.setState({ reactModal: false })}
shouldCloseOnEsc
role="dialog"
ariaHideApp={false}
>
@vinodsobale
vinodsobale / prettier_format_command.json
Created October 4, 2017 06:21
Prettier Format Command
{
"name": "viu-browser-2.0",
"version": "0.1.0",
"private": true,
"devDependencies": {
"prettier": "^1.7.4",
},
"scripts": {
"format": "prettier --write --single-quote --print-width=120 --tab-width=2 \"src/**/*.{js,jsx}\""
},
return (
<th value={column} onClick={() => this.handleSort(column)}>{column}</th>
);
function guid() {
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
s4() + '-' + s4() + s4() + s4();
}
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}