fix: formik bugs and gql upload
This commit is contained in:
parent
3de7ae2fe9
commit
9baa16c824
9 changed files with 56 additions and 64 deletions
|
|
@ -9,6 +9,7 @@ const helmet = require('helmet')
|
||||||
const nocache = require('nocache')
|
const nocache = require('nocache')
|
||||||
const cookieParser = require('cookie-parser')
|
const cookieParser = require('cookie-parser')
|
||||||
const { ApolloServer, AuthenticationError } = require('apollo-server-express')
|
const { ApolloServer, AuthenticationError } = require('apollo-server-express')
|
||||||
|
// const { graphqlUploadExpress } = require('graphql-upload')
|
||||||
const _ = require('lodash/fp')
|
const _ = require('lodash/fp')
|
||||||
|
|
||||||
const { asyncLocalStorage, defaultStore } = require('../async-storage')
|
const { asyncLocalStorage, defaultStore } = require('../async-storage')
|
||||||
|
|
@ -47,6 +48,7 @@ app.use(cleanUserSessions(USER_SESSIONS_CLEAR_INTERVAL))
|
||||||
app.use(computeSchema)
|
app.use(computeSchema)
|
||||||
app.use(findOperatorId)
|
app.use(findOperatorId)
|
||||||
app.use(session)
|
app.use(session)
|
||||||
|
// app.use(graphqlUploadExpress())
|
||||||
|
|
||||||
const apolloServer = new ApolloServer({
|
const apolloServer = new ApolloServer({
|
||||||
typeDefs,
|
typeDefs,
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@ const customers = require('../../../customers')
|
||||||
const filters = require('../../filters')
|
const filters = require('../../filters')
|
||||||
|
|
||||||
const resolvers = {
|
const resolvers = {
|
||||||
|
// Upload: GraphQLUpload,
|
||||||
|
|
||||||
Customer: {
|
Customer: {
|
||||||
isAnonymous: parent => (parent.customerId === anonymous.uuid)
|
isAnonymous: parent => (parent.customerId === anonymous.uuid)
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ const typeDef = gql`
|
||||||
authorizedOverride: String
|
authorizedOverride: String
|
||||||
daysSuspended: Int
|
daysSuspended: Int
|
||||||
isSuspended: Boolean
|
isSuspended: Boolean
|
||||||
frontCamera: String
|
frontCamera: Upload
|
||||||
frontCameraPath: String
|
frontCameraPath: String
|
||||||
frontCameraAt: Date
|
frontCameraAt: Date
|
||||||
frontCameraOverride: String
|
frontCameraOverride: String
|
||||||
|
|
@ -22,7 +22,7 @@ const typeDef = gql`
|
||||||
idCardData: JSONObject
|
idCardData: JSONObject
|
||||||
idCardDataOverride: String
|
idCardDataOverride: String
|
||||||
idCardDataExpiration: Date
|
idCardDataExpiration: Date
|
||||||
idCardPhoto: String
|
idCardPhoto: Upload
|
||||||
idCardPhotoPath: String
|
idCardPhotoPath: String
|
||||||
idCardPhotoOverride: String
|
idCardPhotoOverride: String
|
||||||
usSsn: String
|
usSsn: String
|
||||||
|
|
@ -68,9 +68,9 @@ const typeDef = gql`
|
||||||
}
|
}
|
||||||
|
|
||||||
input CustomerEdit {
|
input CustomerEdit {
|
||||||
frontCamera: String
|
frontCamera: Upload
|
||||||
idCardData: JSONObject
|
idCardData: JSONObject
|
||||||
idCardPhoto: String
|
idCardPhoto: Upload
|
||||||
usSsn: String
|
usSsn: String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,8 @@ exports.up = function (next) {
|
||||||
subscriber_info_edited_at TIMESTAMPTZ,
|
subscriber_info_edited_at TIMESTAMPTZ,
|
||||||
subscriber_info_edited_by UUID REFERENCES users(id),
|
subscriber_info_edited_by UUID REFERENCES users(id),
|
||||||
name TEXT,
|
name TEXT,
|
||||||
name_info_edited_at TIMESTAMPTZ,
|
name_edited_at TIMESTAMPTZ,
|
||||||
name_info_edited_by UUID REFERENCES users(id),
|
name_edited_by UUID REFERENCES users(id),
|
||||||
us_ssn TEXT,
|
us_ssn TEXT,
|
||||||
us_ssn_edited_at TIMESTAMPTZ,
|
us_ssn_edited_at TIMESTAMPTZ,
|
||||||
us_ssn_edited_by UUID REFERENCES users(id),
|
us_ssn_edited_by UUID REFERENCES users(id),
|
||||||
|
|
|
||||||
13
new-lamassu-admin/package-lock.json
generated
13
new-lamassu-admin/package-lock.json
generated
|
|
@ -6888,6 +6888,14 @@
|
||||||
"tslib": "^1.9.3"
|
"tslib": "^1.9.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"apollo-upload-client": {
|
||||||
|
"version": "16.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/apollo-upload-client/-/apollo-upload-client-16.0.0.tgz",
|
||||||
|
"integrity": "sha512-aLhYucyA0T8aBEQ5g+p13qnR9RUyL8xqb8FSZ7e/Kw2KUOsotLUlFluLobqaE7JSUFwc6sKfXIcwB7y4yEjbZg==",
|
||||||
|
"requires": {
|
||||||
|
"extract-files": "^11.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"apollo-utilities": {
|
"apollo-utilities": {
|
||||||
"version": "1.3.4",
|
"version": "1.3.4",
|
||||||
"resolved": "https://registry.npmjs.org/apollo-utilities/-/apollo-utilities-1.3.4.tgz",
|
"resolved": "https://registry.npmjs.org/apollo-utilities/-/apollo-utilities-1.3.4.tgz",
|
||||||
|
|
@ -12608,6 +12616,11 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"extract-files": {
|
||||||
|
"version": "11.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/extract-files/-/extract-files-11.0.0.tgz",
|
||||||
|
"integrity": "sha512-FuoE1qtbJ4bBVvv94CC7s0oTnKUGvQs+Rjf1L2SJFfS+HTVVjhPFtehPdQ0JiGPqVNfSSZvL5yzHHQq2Z4WNhQ=="
|
||||||
|
},
|
||||||
"extsprintf": {
|
"extsprintf": {
|
||||||
"version": "1.3.0",
|
"version": "1.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz",
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
"apollo-link": "^1.2.14",
|
"apollo-link": "^1.2.14",
|
||||||
"apollo-link-error": "^1.1.13",
|
"apollo-link-error": "^1.1.13",
|
||||||
"apollo-link-http": "^1.5.17",
|
"apollo-link-http": "^1.5.17",
|
||||||
|
"apollo-upload-client": "^16.0.0",
|
||||||
"axios": "0.21.1",
|
"axios": "0.21.1",
|
||||||
"base-64": "^1.0.0",
|
"base-64": "^1.0.0",
|
||||||
"bignumber.js": "9.0.0",
|
"bignumber.js": "9.0.0",
|
||||||
|
|
|
||||||
|
|
@ -117,57 +117,36 @@ const CustomerData = ({
|
||||||
{
|
{
|
||||||
name: 'name',
|
name: 'name',
|
||||||
label: 'Name',
|
label: 'Name',
|
||||||
value: `${getName(customer)}`,
|
|
||||||
component: TextInput
|
component: TextInput
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'idNumber',
|
name: 'idNumber',
|
||||||
label: 'ID number',
|
label: 'ID number',
|
||||||
value: R.path(['documentNumber'])(idData) ?? '',
|
|
||||||
component: TextInput
|
component: TextInput
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'birthDate',
|
name: 'birthDate',
|
||||||
label: 'Birth Date',
|
label: 'Birth Date',
|
||||||
value:
|
|
||||||
(rawDob &&
|
|
||||||
format('yyyy-MM-dd')(parse(new Date(), 'yyyyMMdd', rawDob))) ??
|
|
||||||
'',
|
|
||||||
component: TextInput
|
component: TextInput
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'age',
|
name: 'age',
|
||||||
label: 'Age',
|
label: 'Age',
|
||||||
value:
|
|
||||||
(rawDob &&
|
|
||||||
differenceInYears(
|
|
||||||
parse(new Date(), 'yyyyMMdd', rawDob),
|
|
||||||
new Date()
|
|
||||||
)) ??
|
|
||||||
'',
|
|
||||||
component: TextInput
|
component: TextInput
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'gender',
|
name: 'gender',
|
||||||
label: 'Gender',
|
label: 'Gender',
|
||||||
value: R.path(['gender'])(idData) ?? '',
|
|
||||||
component: TextInput
|
component: TextInput
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'state',
|
name: 'state',
|
||||||
label: country === 'Canada' ? 'Province' : 'State',
|
label: country === 'Canada' ? 'Province' : 'State',
|
||||||
value: R.path(['state'])(idData) ?? '',
|
|
||||||
component: TextInput
|
component: TextInput
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'expirationDate',
|
name: 'expirationDate',
|
||||||
label: 'Expiration Date',
|
label: 'Expiration Date',
|
||||||
value:
|
|
||||||
(rawExpirationDate &&
|
|
||||||
format('yyyy-MM-dd')(
|
|
||||||
parse(new Date(), 'yyyyMMdd', rawExpirationDate)
|
|
||||||
)) ??
|
|
||||||
'',
|
|
||||||
component: TextInput
|
component: TextInput
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
@ -176,7 +155,6 @@ const CustomerData = ({
|
||||||
{
|
{
|
||||||
name: 'usSsn',
|
name: 'usSsn',
|
||||||
label: 'US SSN',
|
label: 'US SSN',
|
||||||
value: `${customer.usSsn ?? ''}`,
|
|
||||||
component: TextInput,
|
component: TextInput,
|
||||||
size: 190
|
size: 190
|
||||||
}
|
}
|
||||||
|
|
@ -187,16 +165,17 @@ const CustomerData = ({
|
||||||
|
|
||||||
const initialValues = {
|
const initialValues = {
|
||||||
idScan: {
|
idScan: {
|
||||||
name: '',
|
name: getName(customer) ?? '',
|
||||||
idNumber: '',
|
idNumber: R.path(['documentNumber'])(idData) ?? '',
|
||||||
birthDate: '',
|
birthDate: (rawDob && format('yyyy-MM-dd', rawDob)) ?? '',
|
||||||
age: '',
|
age: (rawDob && differenceInYears(rawDob, new Date())) ?? '',
|
||||||
gender: '',
|
gender: R.path(['gender'])(idData) ?? '',
|
||||||
state: '',
|
state: R.path(['state'])(idData) ?? '',
|
||||||
expirationDate: ''
|
expirationDate:
|
||||||
|
(rawExpirationDate && format('yyyy-MM-dd', rawExpirationDate)) ?? ''
|
||||||
},
|
},
|
||||||
usSsn: {
|
usSsn: {
|
||||||
usSsn: ''
|
usSsn: customer.usSsn ?? ''
|
||||||
},
|
},
|
||||||
frontCamera: {
|
frontCamera: {
|
||||||
frontCamera: null
|
frontCamera: null
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ const fieldStyles = {
|
||||||
|
|
||||||
const fieldUseStyles = makeStyles(fieldStyles)
|
const fieldUseStyles = makeStyles(fieldStyles)
|
||||||
|
|
||||||
const EditableField = ({ editing, field, size, ...props }) => {
|
const EditableField = ({ editing, field, value, size, ...props }) => {
|
||||||
const classes = fieldUseStyles()
|
const classes = fieldUseStyles()
|
||||||
console.log('FIELDDDDDDDD', field)
|
console.log('FIELDDDDDDDD', field)
|
||||||
const classNames = {
|
const classNames = {
|
||||||
|
|
@ -86,7 +86,7 @@ const EditableField = ({ editing, field, size, ...props }) => {
|
||||||
{!editing && (
|
{!editing && (
|
||||||
<>
|
<>
|
||||||
<Label1 className={classes.label}>{field.label}</Label1>
|
<Label1 className={classes.label}>{field.label}</Label1>
|
||||||
<Info3>{field.value}</Info3>
|
<Info3>{value}</Info3>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
{editing && (
|
{editing && (
|
||||||
|
|
@ -96,7 +96,6 @@ const EditableField = ({ editing, field, size, ...props }) => {
|
||||||
className={classes.editing}
|
className={classes.editing}
|
||||||
id={field.name}
|
id={field.name}
|
||||||
name={field.name}
|
name={field.name}
|
||||||
value={field.value}
|
|
||||||
component={field.component}
|
component={field.component}
|
||||||
type={field.type}
|
type={field.type}
|
||||||
width={size}
|
width={size}
|
||||||
|
|
@ -143,8 +142,6 @@ const EditableCard = ({
|
||||||
? { label: 'Rejected', type: 'error' }
|
? { label: 'Rejected', type: 'error' }
|
||||||
: { label: 'Accepted', type: 'success' }
|
: { label: 'Accepted', type: 'success' }
|
||||||
|
|
||||||
const reader = new FileReader()
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Card className={classes.card}>
|
<Card className={classes.card}>
|
||||||
|
|
@ -166,7 +163,10 @@ const EditableCard = ({
|
||||||
enableReinitialize
|
enableReinitialize
|
||||||
validationSchema={validationSchema}
|
validationSchema={validationSchema}
|
||||||
initialValues={initialValues}
|
initialValues={initialValues}
|
||||||
onSubmit={values => save(values)}
|
onSubmit={values => {
|
||||||
|
save(values)
|
||||||
|
setEditing(false)
|
||||||
|
}}
|
||||||
onReset={() => {
|
onReset={() => {
|
||||||
setEditing(false)
|
setEditing(false)
|
||||||
setError(false)
|
setError(false)
|
||||||
|
|
@ -183,6 +183,7 @@ const EditableCard = ({
|
||||||
return idx >= 0 && idx < 4 ? (
|
return idx >= 0 && idx < 4 ? (
|
||||||
<EditableField
|
<EditableField
|
||||||
field={field}
|
field={field}
|
||||||
|
value={initialValues[field.name]}
|
||||||
editing={editing}
|
editing={editing}
|
||||||
size={180}
|
size={180}
|
||||||
/>
|
/>
|
||||||
|
|
@ -195,6 +196,7 @@ const EditableCard = ({
|
||||||
return idx >= 4 ? (
|
return idx >= 4 ? (
|
||||||
<EditableField
|
<EditableField
|
||||||
field={field}
|
field={field}
|
||||||
|
value={initialValues[field.name]}
|
||||||
editing={editing}
|
editing={editing}
|
||||||
size={180}
|
size={180}
|
||||||
/>
|
/>
|
||||||
|
|
@ -245,20 +247,9 @@ const EditableCard = ({
|
||||||
ref={fileInput => setInput(fileInput)}
|
ref={fileInput => setInput(fileInput)}
|
||||||
onChange={event => {
|
onChange={event => {
|
||||||
// need to store it locally if we want to display it even after saving to db
|
// need to store it locally if we want to display it even after saving to db
|
||||||
|
|
||||||
const file = R.head(event.target.files)
|
const file = R.head(event.target.files)
|
||||||
|
if (!file) return
|
||||||
reader.onloadend = () => {
|
setFieldValue(R.head(fields).name, file)
|
||||||
// use a regex to remove data url part
|
|
||||||
setFieldValue(
|
|
||||||
R.head(fields).name,
|
|
||||||
reader.result
|
|
||||||
.replace('data:', '')
|
|
||||||
.replace(/^.+,/, '')
|
|
||||||
)
|
|
||||||
}
|
|
||||||
reader.readAsDataURL(file)
|
|
||||||
event.target.value = null
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
Replace
|
Replace
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import { InMemoryCache } from 'apollo-cache-inmemory'
|
||||||
import { ApolloClient } from 'apollo-client'
|
import { ApolloClient } from 'apollo-client'
|
||||||
import { ApolloLink } from 'apollo-link'
|
import { ApolloLink } from 'apollo-link'
|
||||||
import { onError } from 'apollo-link-error'
|
import { onError } from 'apollo-link-error'
|
||||||
import { HttpLink } from 'apollo-link-http'
|
import { createUploadLink } from 'apollo-upload-client'
|
||||||
import React, { useContext } from 'react'
|
import React, { useContext } from 'react'
|
||||||
import { useHistory, useLocation } from 'react-router-dom'
|
import { useHistory, useLocation } from 'react-router-dom'
|
||||||
|
|
||||||
|
|
@ -15,6 +15,16 @@ const URI =
|
||||||
const ALT_URI =
|
const ALT_URI =
|
||||||
process.env.NODE_ENV === 'development' ? 'http://localhost:4001' : ''
|
process.env.NODE_ENV === 'development' ? 'http://localhost:4001' : ''
|
||||||
|
|
||||||
|
const uploadLink = createUploadLink({
|
||||||
|
credentials: 'include',
|
||||||
|
uri: `${URI}/graphql`
|
||||||
|
})
|
||||||
|
|
||||||
|
const uploadLinkALT = createUploadLink({
|
||||||
|
credentials: 'include',
|
||||||
|
uri: `${ALT_URI}/graphql`
|
||||||
|
})
|
||||||
|
|
||||||
const getClient = (history, location, getUserData, setUserData, setRole) =>
|
const getClient = (history, location, getUserData, setUserData, setRole) =>
|
||||||
new ApolloClient({
|
new ApolloClient({
|
||||||
link: ApolloLink.from([
|
link: ApolloLink.from([
|
||||||
|
|
@ -48,14 +58,8 @@ const getClient = (history, location, getUserData, setUserData, setRole) =>
|
||||||
}),
|
}),
|
||||||
ApolloLink.split(
|
ApolloLink.split(
|
||||||
operation => operation.getContext().clientName === 'pazuz',
|
operation => operation.getContext().clientName === 'pazuz',
|
||||||
new HttpLink({
|
uploadLink,
|
||||||
credentials: 'include',
|
uploadLinkALT
|
||||||
uri: `${ALT_URI}/graphql`
|
|
||||||
}),
|
|
||||||
new HttpLink({
|
|
||||||
credentials: 'include',
|
|
||||||
uri: `${URI}/graphql`
|
|
||||||
})
|
|
||||||
)
|
)
|
||||||
]),
|
]),
|
||||||
cache: new InMemoryCache(),
|
cache: new InMemoryCache(),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue