From 456c35fd719a2ed24d1cd060aa677f160db581b7 Mon Sep 17 00:00:00 2001 From: tony-tvu Date: Mon, 9 May 2022 16:59:58 -0500 Subject: [PATCH 1/3] convert file to ts and refactor types and methods --- web/src/app/main/components/NewUserSetup.js | 6 ++-- ...g.js => UserContactMethodCreateDialog.tsx} | 34 +++++++++++-------- web/src/app/users/UserContactMethodForm.tsx | 5 ++- web/src/app/users/UserDetails.js | 6 ++-- 4 files changed, 28 insertions(+), 23 deletions(-) rename web/src/app/users/{UserContactMethodCreateDialog.js => UserContactMethodCreateDialog.tsx} (85%) diff --git a/web/src/app/main/components/NewUserSetup.js b/web/src/app/main/components/NewUserSetup.js index 606ba6448e..0f5020bf1e 100644 --- a/web/src/app/main/components/NewUserSetup.js +++ b/web/src/app/main/components/NewUserSetup.js @@ -29,9 +29,9 @@ export default function NewUserSetup() { subtitle='To get started, please enter a contact method.' disclaimer={disclaimer} userID={userID} - onClose={(result) => { - if (result && result.contactMethodID) { - setContactMethodID(result) + onClose={(contactMethodID) => { + if (contactMethodID) { + setContactMethodID(contactMethodID) } else { clearIsFirstLogin() } diff --git a/web/src/app/users/UserContactMethodCreateDialog.js b/web/src/app/users/UserContactMethodCreateDialog.tsx similarity index 85% rename from web/src/app/users/UserContactMethodCreateDialog.js rename to web/src/app/users/UserContactMethodCreateDialog.tsx index 82ccea01a5..7dcf5dd0ab 100644 --- a/web/src/app/users/UserContactMethodCreateDialog.js +++ b/web/src/app/users/UserContactMethodCreateDialog.tsx @@ -1,6 +1,5 @@ import React, { useState } from 'react' import { useMutation, useLazyQuery, gql } from '@apollo/client' -import p from 'prop-types' import { fieldErrors, nonFieldErrors } from '../util/errutil' import FormDialog from '../dialogs/FormDialog' @@ -8,6 +7,13 @@ import UserContactMethodForm from './UserContactMethodForm' import { useConfigValue } from '../util/RequireConfig' import { Dialog, DialogTitle, DialogActions, Button } from '@mui/material' import DialogContentError from '../dialogs/components/DialogContentError' +import { ContactMethodType } from '../../schema' + +type Value = { + name: string + type: ContactMethodType + value: string +} const createMutation = gql` mutation ($input: CreateUserContactMethodInput!) { @@ -28,13 +34,19 @@ const userConflictQuery = gql` } ` -export default function UserContactMethodCreateDialog(props) { +export default function UserContactMethodCreateDialog(props: { + userID: string + onClose: (contactMethodID?: string) => void + disclaimer: string + title: string + subtitle: string +}): JSX.Element { const [allowSV, allowE, allowW] = useConfigValue( 'Twilio.Enable', 'SMTP.Enable', 'Webhook.Enable', ) - let typeVal = '' + let typeVal: ContactMethodType = 'SMS' if (allowSV) { typeVal = 'SMS' } else if (allowE) { @@ -43,7 +55,7 @@ export default function UserContactMethodCreateDialog(props) { typeVal = 'WEBHOOK' } // values for contact method form - const [CMValue, setCMValue] = useState({ + const [CMValue, setCMValue] = useState({ name: '', type: typeVal, value: '', @@ -64,9 +76,9 @@ export default function UserContactMethodCreateDialog(props) { const [createCM, createCMStatus] = useMutation(createMutation, { onCompleted: (result) => { - props.onClose({ contactMethodID: result.createUserContactMethod.id }) + props.onClose(result.createUserContactMethod.id) }, - onError: query, + onError: () => query(), variables: { input: { ...CMValue, @@ -115,7 +127,7 @@ export default function UserContactMethodCreateDialog(props) { setCMValue(CMValue)} + onChange={(CMValue: Value) => setCMValue(CMValue)} value={CMValue} disclaimer={props.disclaimer} /> @@ -135,11 +147,3 @@ export default function UserContactMethodCreateDialog(props) { /> ) } - -UserContactMethodCreateDialog.propTypes = { - userID: p.string.isRequired, - onClose: p.func, - disclaimer: p.string, - title: p.string, - subtitle: p.string, -} diff --git a/web/src/app/users/UserContactMethodForm.tsx b/web/src/app/users/UserContactMethodForm.tsx index 33b39930af..00868f3670 100644 --- a/web/src/app/users/UserContactMethodForm.tsx +++ b/web/src/app/users/UserContactMethodForm.tsx @@ -6,6 +6,7 @@ import TelTextField from '../util/TelTextField' import { MenuItem, Typography } from '@mui/material' import { ContactMethodType } from '../../schema' import { useConfigValue } from '../util/RequireConfig' +import { FieldError } from '../util/errutil' type Value = { name: string @@ -17,10 +18,12 @@ export type UserContactMethodFormProps = { value: Value disclaimer?: string - errors?: Array<{ field: 'name' | 'type' | 'value'; message: string }> + errors?: Array disabled?: boolean edit?: boolean + + onChange?: (CMValue: Value) => void } function renderEmailField(edit: boolean): JSX.Element { diff --git a/web/src/app/users/UserDetails.js b/web/src/app/users/UserDetails.js index 7bf871bc4b..f6dd2f18a4 100644 --- a/web/src/app/users/UserDetails.js +++ b/web/src/app/users/UserDetails.js @@ -186,11 +186,9 @@ export default function UserDetails(props) { { + onClose={(contactMethodID) => { setCreateCM(false) - setShowVerifyDialogByID( - result && result.contactMethodID ? result.contactMethodID : null, - ) + setShowVerifyDialogByID(contactMethodID) }} /> )} From c897d17f0624078b31b79f5a16fe2a9947b283cb Mon Sep 17 00:00:00 2001 From: tony-tvu Date: Thu, 12 May 2022 14:55:03 -0500 Subject: [PATCH 2/3] change default value --- web/src/app/users/UserContactMethodCreateDialog.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/app/users/UserContactMethodCreateDialog.tsx b/web/src/app/users/UserContactMethodCreateDialog.tsx index 7dcf5dd0ab..b00805ae21 100644 --- a/web/src/app/users/UserContactMethodCreateDialog.tsx +++ b/web/src/app/users/UserContactMethodCreateDialog.tsx @@ -46,7 +46,7 @@ export default function UserContactMethodCreateDialog(props: { 'SMTP.Enable', 'Webhook.Enable', ) - let typeVal: ContactMethodType = 'SMS' + let typeVal: ContactMethodType = 'VOICE' if (allowSV) { typeVal = 'SMS' } else if (allowE) { From 922e36bcd36adc50c876e0d7df2ae5c117e8e007 Mon Sep 17 00:00:00 2001 From: tony-tvu Date: Mon, 23 May 2022 15:17:20 -0500 Subject: [PATCH 3/3] resolve breaking cypress test --- web/src/app/main/components/NewUserSetup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/app/main/components/NewUserSetup.js b/web/src/app/main/components/NewUserSetup.js index 0f5020bf1e..ceef17df3e 100644 --- a/web/src/app/main/components/NewUserSetup.js +++ b/web/src/app/main/components/NewUserSetup.js @@ -17,7 +17,7 @@ export default function NewUserSetup() { if (contactMethodID) { return ( )