Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: different validation rules for the cover file #352

Merged
merged 4 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion src/components/form/FormFields.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import Select from '@atoms/select/Base'
import styles from '@style'
import { memo } from 'react'
import { Upload } from '@components/upload/index'
import { ALLOWED_FILETYPES_LABEL } from '@constants'
import {
ALLOWED_FILETYPES_LABEL,
ALLOWED_COVER_FILETYPES_LABEL,
} from '@constants'
import { Controller } from 'react-hook-form'
import classNames from 'classnames'

Expand Down Expand Up @@ -113,6 +116,31 @@ export const FormFields = ({ value, field, error, register, control }) => {
)}
/>
)

case 'cover-file':
return (
<Controller
control={control}
defaultValue={field.defaultValue}
name={name}
rules={field.rules}
render={({ field: { onChange, value, name, ref } }) => (
<Upload
ref={ref}
name={name}
file={value?.file}
label={field.label}
placeHolder={value ? value?.file?.name : field.placeHolder}
className={styles.field}
onChange={onChange}
allowedTypesLabel={ALLOWED_COVER_FILETYPES_LABEL}
>
{error && <FieldError error={error.message} />}
</Upload>
)}
/>
)

default:
return (
<p>
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const ALLOWED_COVER_MIMETYPES = [
MIMETYPE.MP4,
]

export const ALLOWED_COVER_FILETYPES_LABEL = ['jpeg, png, gif']
export const ALLOWED_COVER_FILETYPES_LABEL = 'jpeg, png, gif, mp4'
export const MAX_EDITIONS = 10000 // Limited by contract
export const MIN_ROYALTIES = 10
export const MAX_ROYALTIES = 25
Expand Down
10 changes: 10 additions & 0 deletions src/context/mintStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { useModalStore } from './modalStore'
import {
ALLOWED_FILETYPES_LABEL,
ALLOWED_MIMETYPES,
ALLOWED_COVER_FILETYPES_LABEL,
ALLOWED_COVER_MIMETYPES,
METADATA_ACCESSIBILITY_HAZARDS_PHOTOSENS,
METADATA_CONTENT_RATING_MATURE,
MIMETYPE,
Expand Down Expand Up @@ -128,6 +130,14 @@ export const useMintStore = create<MintState>()(
return
}

// check cover mime type
if (cover && !ALLOWED_COVER_MIMETYPES.includes(cover.mimeType)) {
show(
`Cover file format invalid. supported formats include: ${ALLOWED_COVER_FILETYPES_LABEL.toLocaleLowerCase()}`
)
return
}

// check file size
const filesize = parseInt(
(artifact.file.size / 1024 / 1024).toFixed(4)
Expand Down
2 changes: 1 addition & 1 deletion src/pages/mint/fields.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export const fields = [
label: 'Cover Image',
placeHolder: 'Upload Cover image',
name: 'cover',
type: 'file',
type: 'cover-file',
watch: true,
enable_if: 'needsCover',
rules: {
Expand Down