Skip to content

Instantly share code, notes, and snippets.

View parwatcodes's full-sized avatar

Parwat Kunwar parwatcodes

View GitHub Profile
// Array of timesheet for the selected week. from = "02-02-2020", to = "08-02-2020"
const timeSheetData = [
{
id: "P-011",
taskId: "T-011",
// more fields such as taskname, projectname and more
timeEntriesForWeek: {
"02-02-2020": 1,
"03-02-2020": 4,
const weeklyTimeSheetData = [
{
id: "P-011",
taskId: "T-011",
timeEntriesForWeek: {}
},
{
id: "P-012",
taskId: "T-70",
timeEntriesForWeek: {}
@parwatcodes
parwatcodes / react-props-inline-conditional.js
Created July 8, 2019 11:17
react-inline-conditionally-pass-prop-to-component
const { editable, editableOpts } = this.props;
return (
<Child {...(editable && { editable: editableOpts } )} />
);
const getInitialValues = props => {
const {company} = props
const filteredData = {...company}
if (company && company.companyCategory) {
const {
companyCategory: {id},
} = company
delete filteredData.companyCategory
filteredData.companyCategoryId = parseInt(id, 10)
}
/* eslint-disable jsx-a11y/label-has-for */
import React from 'react';
import { capitalizeFirstLetters } from 'Utils';
type Props = {
name: string,
label: string,
options: Object,
idKey: string,
nameKey: string,
console.log([false, null, 2, 0, undefined].filter(Boolean));
const isRequired = () => { throw new Error('param is required'); };
const hello = (name = isRequired()) => { console.log(`hello ${name}`) };
=> #<Client:0x00007fc6b1d7f0f8
id: 35,
company_name: "Moneyballok",
company_url: "www.mvnbasfi.com",
company_email: "parwat+1qw@whitehatengineering.com",
company_size: nil,
phone_number: nil,
fax: nil,
address: nil,
address_alt: nil,
@parwatcodes
parwatcodes / hoc.js
Created April 2, 2019 18:34
a example for higher order component
// presentational component
const Greeting = ({ name }) => {
if (!name) {
return <div>Connecting...</div>;
}
return <div>Hi {name}!</div>;
};
// hoc
@parwatcodes
parwatcodes / validate_phone.js
Last active December 16, 2019 11:22
phone number validation
function validate(phone) {
var regex = /^\+(?:[0-9]?){6,14}[0-9]$/;
if (regex.test(phone)) {
// Valid international phone number
return 'valid'
} else {
return 'invalid'
// Invalid international phone number
}