Skip to content

Commit

Permalink
Rename errorCode to rejectedCode
Browse files Browse the repository at this point in the history
  • Loading branch information
yosipy committed Jul 28, 2024
1 parent 3f80837 commit 6e06048
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion docs/examples/accepting-specific-file-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const Accept: FC = () => {
<span key={index}>
<li>{fileRejection.file.name}</li>
<ul>
<li>{fileRejection.errorCode}</li>
<li>{fileRejection.rejectedCode}</li>
</ul>
</span>
))}
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/accepting-specific-file-types/Accept.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const Accept: FC = () => {
<span key={index}>
<li>{fileRejection.file.name}</li>
<ul>
<li>{fileRejection.errorCode}</li>
<li>{fileRejection.rejectedCode}</li>
</ul>
</span>
))}
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/basic-example.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const Basic: FC = () => {
<span key={index}>
<li>{fileRejection.file.name}</li>
<ul>
<li>{fileRejection.errorCode}</li>
<li>{fileRejection.rejectedCode}</li>
</ul>
</span>
))}
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/basic-example/Basic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const Basic: FC = () => {
<span key={index}>
<li>{fileRejection.file.name}</li>
<ul>
<li>{fileRejection.errorCode}</li>
<li>{fileRejection.rejectedCode}</li>
</ul>
</span>
))}
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/custom-validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const CustomValidation: FC = () => {
const fileRejection: ClassifiedFile = {
status: "rejected",
file,
errorCode: "name-too-longer",
rejectedCode: "name-too-longer",
}
return fileRejection
}
Expand Down Expand Up @@ -93,7 +93,7 @@ export const CustomValidation: FC = () => {
<span key={index}>
<li>{fileRejection.file.name}</li>
<ul>
<li>{fileRejection.errorCode}</li>
<li>{fileRejection.rejectedCode}</li>
</ul>
</span>
))}
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/custom-validation/CustomValidation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const CustomValidation: FC = () => {
const fileRejection: ClassifiedFile = {
status: "rejected",
file,
errorCode: "name-too-longer",
rejectedCode: "name-too-longer",
}
return fileRejection
}
Expand Down Expand Up @@ -71,7 +71,7 @@ export const CustomValidation: FC = () => {
<span key={index}>
<li>{fileRejection.file.name}</li>
<ul>
<li>{fileRejection.errorCode}</li>
<li>{fileRejection.rejectedCode}</li>
</ul>
</span>
))}
Expand Down
2 changes: 1 addition & 1 deletion docs/introduction/Introduction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const Introduction: FC = () => {
<span key={index}>
<li>{fileRejection.file.name}</li>
<ul>
<li>{fileRejection.errorCode}</li>
<li>{fileRejection.rejectedCode}</li>
</ul>
</span>
))}
Expand Down
2 changes: 1 addition & 1 deletion docs/introduction/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const Introduction: FC = () => {
<span key={index}>
<li>{fileRejection.file.name}</li>
<ul>
<li>{fileRejection.errorCode}</li>
<li>{fileRejection.rejectedCode}</li>
</ul>
</span>
))}
Expand Down
4 changes: 2 additions & 2 deletions docs/introduction/hooks-and-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ export type RejectedCode = "more-than-one-file" | "accept-violations"
export type AcceptedClassifiedFile = {
status: "accepted"
file: File
errorCode: undefined
rejectedCode: undefined
}

export type RejectedClassifiedFile = {
status: "rejected"
file: File
errorCode: RejectedCode | string
rejectedCode: RejectedCode | string
}

export type ClassifiedFile = AcceptedClassifiedFile | RejectedClassifiedFile
Expand Down
4 changes: 2 additions & 2 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ export type RejectedCode = "more-than-one-file" | "accept-violations"
export type AcceptedClassifiedFile = {
status: "accepted"
file: File
errorCode: undefined
rejectedCode: undefined
}

export type RejectedClassifiedFile<T extends string = string> = {
status: "rejected"
file: File
errorCode: T
rejectedCode: T
}

export type ClassifiedFile<T extends string = string> =
Expand Down
30 changes: 15 additions & 15 deletions lib/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ describe("classifyByAcceptability", () => {
const multiple = false

describe("If input one file", () => {
test("Status should be accepted and errorCode should be undefined", () => {
test("Status should be accepted and rejectedCode should be undefined", () => {
const classifiedFiles = classifyByAcceptability([textFile], {
accept: "text/plain",
multiple,
Expand All @@ -161,14 +161,14 @@ describe("classifyByAcceptability", () => {
{
status: "accepted",
file: textFile,
errorCode: undefined,
rejectedCode: undefined,
},
])
})
})

describe("If input multi files", () => {
test("Status should be rejected and errorCode should be more-than-one-file", () => {
test("Status should be rejected and rejectedCode should be more-than-one-file", () => {
const classifiedFiles = classifyByAcceptability([textFile, jsFile], {
accept: "image/png",
multiple,
Expand All @@ -177,12 +177,12 @@ describe("classifyByAcceptability", () => {
{
status: "rejected",
file: textFile,
errorCode: "more-than-one-file",
rejectedCode: "more-than-one-file",
},
{
status: "rejected",
file: jsFile,
errorCode: "more-than-one-file",
rejectedCode: "more-than-one-file",
},
])
})
Expand All @@ -193,7 +193,7 @@ describe("classifyByAcceptability", () => {
const multiple = true

describe("If input files mimeType is included options.accept", () => {
test("Status should be accepted and errorCode should be undefined", () => {
test("Status should be accepted and rejectedCode should be undefined", () => {
const classifiedFiles = classifyByAcceptability([textFile, jsFile], {
accept: "text/*",
multiple,
Expand All @@ -202,19 +202,19 @@ describe("classifyByAcceptability", () => {
{
status: "accepted",
file: textFile,
errorCode: undefined,
rejectedCode: undefined,
},
{
status: "accepted",
file: jsFile,
errorCode: undefined,
rejectedCode: undefined,
},
])
})
})

describe("If input file mimeType is not included options.accept", () => {
test("Status should be rejected and errorCode should be accept-violations", () => {
test("Status should be rejected and rejectedCode should be accept-violations", () => {
const classifiedFiles = classifyByAcceptability([textFile, jsFile], {
accept: "image/png",
multiple,
Expand All @@ -223,12 +223,12 @@ describe("classifyByAcceptability", () => {
{
status: "rejected",
file: textFile,
errorCode: "accept-violations",
rejectedCode: "accept-violations",
},
{
status: "rejected",
file: jsFile,
errorCode: "accept-violations",
rejectedCode: "accept-violations",
},
])
})
Expand All @@ -243,17 +243,17 @@ describe("splitClassifiedFiles", () => {
{
status: "accepted",
file: new File(["hoge"], "accepted1.txt", { type: "text/plain" }),
errorCode: undefined,
rejectedCode: undefined,
},
{
status: "accepted",
file: new File(["hoge"], "accepted2.txt", { type: "text/plain" }),
errorCode: undefined,
rejectedCode: undefined,
},
{
status: "rejected",
file: new File(["hoge"], "rejected.txt", { type: "text/plain" }),
errorCode: "accept-violations",
rejectedCode: "accept-violations",
},
]
})
Expand All @@ -270,7 +270,7 @@ describe("splitClassifiedFiles", () => {
{
status: "rejected",
file: new File(["hoge"], "rejected.txt", { type: "text/plain" }),
errorCode: "accept-violations",
rejectedCode: "accept-violations",
},
])
})
Expand Down
6 changes: 3 additions & 3 deletions lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const classifyByAcceptability = (
return {
status: "rejected",
file: file,
errorCode: "more-than-one-file",
rejectedCode: "more-than-one-file",
}
})

Expand All @@ -86,13 +86,13 @@ export const classifyByAcceptability = (
classifiedFiles.push({
status: "accepted",
file: file,
errorCode: undefined,
rejectedCode: undefined,
})
} else {
classifiedFiles.push({
status: "rejected",
file: file,
errorCode: "accept-violations",
rejectedCode: "accept-violations",
})
}
}
Expand Down

0 comments on commit 6e06048

Please sign in to comment.