Skip to content

Commit

Permalink
[CLD-518] Show messages when developer has reached too many unlisted …
Browse files Browse the repository at this point in the history
…apps (#191)
  • Loading branch information
dannd4 authored Dec 5, 2019
1 parent 92c38a8 commit 99f36ce
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 17 deletions.
4 changes: 3 additions & 1 deletion src/actions/submit-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { CreateAppModel, ScopeModel } from '@/types/marketplace-api-schema'
import { FormState } from '@/types/core'

export type SubmitAppFormikActions = FormikHelpers<CreateAppModel>
export type SubmitAppArgs = CreateAppModel & { actions: SubmitAppFormikActions }
export type SubmitAppArgs = CreateAppModel & { actions: SubmitAppFormikActions } & {
setSubmitError: (error: string) => void
}

export const submitApp = actionCreator<SubmitAppArgs>(ActionTypes.DEVELOPER_SUBMIT_APP)
export const submitAppSetFormState = actionCreator<FormState>(ActionTypes.DEVELOPER_SUBMIT_APP_SET_FORM_STATE)
Expand Down
40 changes: 27 additions & 13 deletions src/components/pages/developer-submit-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import {
SelectBoxOptions,
Formik,
Form,
FormikHelpers
FormikHelpers,
H6,
FormikValues
} from '@reapit/elements'

import { validate } from '@/utils/form/submit-app'
Expand All @@ -39,7 +41,11 @@ import DeveloperSubmitAppSuccessfully from './developer-submit-app-successfully'
import { selectCategories } from '../../selector/app-categories'

export interface SubmitAppMappedActions {
submitApp: (appModel: CreateAppModel, actions: SubmitAppFormikActions) => void
submitApp: (
appModel: CreateAppModel,
actions: SubmitAppFormikActions,
setSubmitError: (error: string) => void
) => void
submitAppSetFormState: (formState: FormState) => void
submitRevision: (id: string, revision: CreateAppModel) => void
submitRevisionSetFormState: (formState: FormState) => void
Expand Down Expand Up @@ -134,6 +140,17 @@ export const generateInitialValues = (appDetail: AppDetailModel | null, develope
return initialValues
}

export const handleSubmitApp = ({ appId, submitApp, submitRevision, setSubmitError }) => (
appModel: CreateAppModel,
actions: FormikHelpers<CreateAppModel>
) => {
if (!appId) {
submitApp(appModel, actions, setSubmitError)
} else {
submitRevision(appId, appModel)
}
}

export const SubmitApp: React.FC<SubmitAppProps> = ({
submitAppSetFormState,
submitApp,
Expand All @@ -149,7 +166,9 @@ export const SubmitApp: React.FC<SubmitAppProps> = ({
}) => {
let initialValues
let formState
let appid
let appId

const [submitError, setSubmitError] = React.useState<string>()

const isSubmitRevision = Boolean(match.params && match.params.appid)
const isSubmitApp = !isSubmitRevision
Expand Down Expand Up @@ -181,7 +200,7 @@ export const SubmitApp: React.FC<SubmitAppProps> = ({
return null
}

appid = appDetailData.data.id
appId = appDetailData.data.id
initialValues = generateInitialValues(appDetailData.data, developerId)
}

Expand Down Expand Up @@ -219,13 +238,7 @@ export const SubmitApp: React.FC<SubmitAppProps> = ({
<Formik
validate={validate}
initialValues={initialValues}
onSubmit={(appModel: CreateAppModel, actions: FormikHelpers<CreateAppModel>) => {
if (!appid) {
submitApp(appModel, actions)
} else {
submitRevision(appid, appModel)
}
}}
onSubmit={handleSubmitApp({ appId, submitApp, submitRevision, setSubmitError })}
>
{() => {
return (
Expand Down Expand Up @@ -412,6 +425,7 @@ export const SubmitApp: React.FC<SubmitAppProps> = ({
</FormSection>
<FormSection>
<LevelRight>
{submitError && <H6 className="has-text-danger mr-5">{submitError}</H6>}
<Button
type="submit"
dataTest="submit-app-button"
Expand Down Expand Up @@ -448,8 +462,8 @@ const mapStateToProps = (state: ReduxState): SubmitAppMappedProps => ({
})

const mapDispatchToProps = (dispatch: any): SubmitAppMappedActions => ({
submitApp: (appModel: CreateAppModel, actions: SubmitAppFormikActions) => {
dispatch(submitApp({ ...appModel, actions }))
submitApp: (appModel: CreateAppModel, actions: SubmitAppFormikActions, setSubmitError: (error: string) => void) => {
dispatch(submitApp({ ...appModel, actions, setSubmitError }))
},
submitRevision: (id, revision) => {
dispatch(submitRevision({ ...revision, id }))
Expand Down
6 changes: 5 additions & 1 deletion src/constants/error-messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ const errorMessages = {
MINIMUM_CHARACTER_LENGTH: (min: number) => `The minimum length is ${min} characters`,
MAXIMUM_CHARACTER_LENGTH: (max: number) => `The maximum length is ${max} characters`,
FIELD_INVALID_PASSWORD:
'Your Password should be a minimum of 8 characters; must contain at least one lowercase letter, one uppercase letter and one number.'
'Your Password should be a minimum of 8 characters; must contain at least one lowercase letter, one uppercase letter and one number.',
SERVER_LIMIT_UNLISTED_APPS:
'Unable to register client app: Limit of unlisted apps against this account has been reached',
CLIENT_LIMIT_UNLISTED_APPS:
'We are unable to process this submission. You currently have reached your limit of unlisted apps. Please edit your existing apps to continue.'
}

export default errorMessages
9 changes: 7 additions & 2 deletions src/sagas/submit-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const imageUploaderHelper = async (object: ImageUploaderReq) => {
}

export const submitApp = function*({ data }: Action<SubmitAppArgs>) {
const { actions, ...values } = data
const { actions, setSubmitError, ...values } = data
actions.setStatus(undefined)

yield put(submitAppSetFormState('SUBMITTING'))
Expand Down Expand Up @@ -75,11 +75,16 @@ export const submitApp = function*({ data }: Action<SubmitAppArgs>) {
console.error(err)

if (err instanceof FetchError) {
const response = err.response as unknown
const response = err.response as any
const formErrors = getApiErrorsFromResponse(response as ApiFormErrorsResponse)

if (formErrors) {
actions.setErrors(formErrors)
}

if (response.description === errorMessages.SERVER_LIMIT_UNLISTED_APPS) {
setSubmitError(errorMessages.CLIENT_LIMIT_UNLISTED_APPS)
}
}

yield put(submitAppSetFormState('ERROR'))
Expand Down

0 comments on commit 99f36ce

Please sign in to comment.