Skip to content

Instantly share code, notes, and snippets.

View pratikagashe's full-sized avatar

Pratik pratikagashe

View GitHub Profile
@pratikagashe
pratikagashe / formikDemo.js
Last active July 11, 2022 17:28
FromikDemo
import React, { useState } from 'react'
import {
Grid,
TextField,
Button,
makeStyles,
createStyles,
Theme,
} from '@material-ui/core'
import { Formik, Form, FormikProps } from 'formik'
@pratikagashe
pratikagashe / yupValidationSchema.js
Created May 15, 2020 12:45
Formik validate vs yup validation schema
// With Yup validationSchema
validationSchema={Yup.object().shape({
email: Yup.string()
.email()
.required('Enter valid email-id'),
})}
// With Formik Validate
validate={values => {
const errors = {};
@pratikagashe
pratikagashe / timezoneConvert.js
Created May 4, 2020 10:07
Converting the Date into different time zone with DST check
const d = new Date()
// convert to msec since Jan 1 1970
const localTime = d.getTime()
// obtain local UTC offset and convert to msec
const localOffset = d.getTimezoneOffset() * 60 * 1000
// obtain UTC time in msec
const utcTime = localTime + localOffset
@pratikagashe
pratikagashe / dateFormat.js
Created May 2, 2020 11:53
Common date format method
const d = new Date()
const date = d.getDate()
const month = d.getMonth()
const year = d.getFullYear()
return date + '/' + (month + 1) + '/' + year
// which will return somethig like 2/5/2020
@pratikagashe
pratikagashe / omit_cammands
Created February 27, 2020 11:48
graphql omit cammands
comment on table public.knex_migrations is E'@name knex_migrations\n@omit create,update,delete\nThis is the documentation.';
comment on table public.knex_migrations_lock is E'@name knex_migrations_lock\n@omit create,update,delete\nThis is the documentation.';
@pratikagashe
pratikagashe / services.ts
Created February 26, 2020 07:55
utils/services.ts : postgraphile demo
import {
useUpdateUserByIdMutation,
useGetUsersQuery,
} from '../generated/graphql'
export const useGetUsers = useGetUsersQuery
export const useUpdateUserById = useUpdateUserByIdMutation
@pratikagashe
pratikagashe / UpdateUser.tsx
Last active February 26, 2020 08:00
client UpdateUser for mutation: postgraphile demo
import React, { useState, useEffect } from 'react'
import { useUpdateUserById } from '../utils/services'
interface updateUser {
id: number
name: string
}
const UpdateUser = (props: updateUser) => {
const [updateUserById] = useUpdateUserById()
@pratikagashe
pratikagashe / Users.tsx
Last active February 26, 2020 08:01
client users component updated: postgraphile demo
import React, { useState, useEffect } from 'react'
import { useGetUsers } from '../utils/services'
import { User } from '../generated/graphql'
import UpdateUser from './UpdateUser'
const Users: React.FC = () => {
const [users, setUsers] = useState()
const { data, error, loading } = useGetUsers()
const [values, setValues] = useState({
id: 0,
@pratikagashe
pratikagashe / updateUserById.mutation.ts
Created February 25, 2020 13:38
graphql mutation to updateUserById: postgraphile demo
import gql from 'graphql-tag'
export default gql`
mutation updateUserById($id: Int!, $UserPatch: UserPatch!) {
updateUserById(input: { id: $id, userPatch: $UserPatch }) {
clientMutationId
}
}
`
@pratikagashe
pratikagashe / Users.tsx
Created February 24, 2020 13:58
client Users.tsx graphql query: postgraphile demo
import React, { useState, useEffect } from 'react'
import { useGetUsersQuery, User } from '../generated/graphql'
const Users: React.FC = () => {
const [users, setUsers] = useState()
const { data, error, loading } = useGetUsersQuery()
useEffect(() => {
if (data) {
if (data && data.allUsers && data.allUsers.nodes) {