Skip to content

Commit

Permalink
[C-4899] Fix isrc and iswc validation (#9352)
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanjeffers authored Aug 1, 2024
1 parent 7c780e8 commit 9500340
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
23 changes: 20 additions & 3 deletions packages/mobile/src/screens/edit-track-screen/EditTrackScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ const errorMessages = {
previewStartZero:
'Preview must start at 0 since the track is less than 30 seconds.',
bpmTooLow: `BPM less than ${MIN_BPM}`,
bpmTooHigh: `BPM greater than ${MAX_BPM}`
bpmTooHigh: `BPM greater than ${MAX_BPM}`,
isrc: "Invalid ISRC. Must be in the format 'CC-XXX-YY-NNNNN'",
iswc: "Invalid ISWC. Must be in the format 'T-34524688-1'"
}

const useEditTrackSchema = () => {
Expand Down Expand Up @@ -66,7 +68,22 @@ const useEditTrackSchema = () => {
stream_conditions: z.any(),
duration: z.number().nullable(),
preview_start_seconds: z.any(),
bpm: z.optional(z.string().nullable())
bpm: z.optional(z.string().nullable()),
isrc: z.optional(
z
.string()
.regex(
/^[A-Z]{2}-?[A-Z\d]{3}-?\d{2}-?\d{5}$/i,
errorMessages.isrc
)
.nullable()
),
iswc: z.optional(
z
.string()
.regex(/^T-?\d{3}.?\d{3}.?\d{3}.?-?\d$/i, errorMessages.iswc)
.nullable()
)
})
.refine(
(values) => {
Expand All @@ -88,7 +105,7 @@ const useEditTrackSchema = () => {
(values) => {
return typeof values.genre === 'string' && !!values.genre
},
{ message: errorMessages.description, path: ['genre'] }
{ message: errorMessages.genre, path: ['genre'] }
)
.refine(
(values) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { useFormikContext } from 'formik'
import { View } from 'react-native'

import { IconInfo } from '@audius/harmony-native'
import { TextField } from 'app/components/fields'
import { FormScreen } from 'app/screens/form-screen'
import { makeStyles } from 'app/styles'

import type { FormValues } from '../types'

const messages = {
title: 'ISRC/ISWC',
isrc: 'ISRC',
Expand All @@ -20,18 +23,31 @@ const useStyles = makeStyles(({ spacing }) => ({

export const IsrcIswcScreen = () => {
const styles = useStyles()

const { errors } = useFormikContext<FormValues>()

const hasErrors = Boolean(errors.isrc || errors.iswc)

return (
<FormScreen title={messages.title} icon={IconInfo} variant='white'>
<FormScreen
title={messages.title}
icon={IconInfo}
variant='white'
disableSubmit={hasErrors}
revertOnCancel
>
<View style={styles.content}>
<TextField
name='isrc'
label={messages.isrc}
placeholder='CC-XXX-YY-NNNNN'
errorBeforeSubmit
/>
<TextField
name='iswc'
label={messages.iswc}
placeholder='T-34524688-1'
errorBeforeSubmit
/>
</View>
</FormScreen>
Expand Down

0 comments on commit 9500340

Please sign in to comment.