-
Notifications
You must be signed in to change notification settings - Fork 1
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
Validation #2
Merged
Merged
Validation #2
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8659c06
made some changes but image upload pending
tasbi03 6b7c798
file upload working, still some more validation to do
tasbi03 00f183b
upload file done
tasbi03 d42d6e9
made some changes
tasbi03 7dc6b27
made changes as requested
tasbi03 5ef1c5c
final changes
tasbi03 7773d34
Requested changes done and cleaned up the code
tasbi03 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,27 @@ | ||
import { Flow, RcbUserSubmitTextEvent } from "react-chatbotify"; | ||
import { Flow, RcbUserSubmitTextEvent, RcbUserUploadFileEvent } from "react-chatbotify"; | ||
import { InputValidatorBlock } from "../types/InputValidatorBlock"; | ||
import { ValidationResult } from "../types/ValidationResult"; | ||
|
||
/** | ||
* Retrieves the validator function and returns null if not applicable. | ||
* Union type for user events that can be validated. | ||
*/ | ||
export const getValidator = (event: RcbUserSubmitTextEvent, currBotId: string | null, currFlow: Flow) => { | ||
if (currBotId !== event.detail.botId) { | ||
return; | ||
} | ||
|
||
if (!event.detail.currPath) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm any reason this was removed in favour of splitting into 2 separate checks? |
||
type RcbUserEvent = RcbUserSubmitTextEvent | RcbUserUploadFileEvent; | ||
|
||
/** | ||
* Retrieves the validator function from the current flow block. | ||
* | ||
* @param event The event emitted by the user action (text submission or file upload). | ||
* @param currBotId The current bot ID. | ||
* @param currFlow The current flow object. | ||
* @returns The validator function if it exists, otherwise undefined. | ||
*/ | ||
export const getValidator = <T = string | File>( | ||
event: RcbUserEvent, | ||
currBotId: string | null, | ||
currFlow: Flow, | ||
validatorType: "validateTextInput" | "validateFileInput" = "validateTextInput" | ||
): ((input: T) => ValidationResult) | undefined => { | ||
if (!event.detail?.currPath || currBotId !== event.detail.botId) { | ||
return; | ||
} | ||
|
||
|
@@ -18,12 +30,6 @@ export const getValidator = (event: RcbUserSubmitTextEvent, currBotId: string | | |
return; | ||
} | ||
|
||
const validator = currBlock.validateInput; | ||
const isValidatorFunction = | ||
validator && typeof validator === "function"; | ||
if (!isValidatorFunction) { | ||
return; | ||
} | ||
|
||
return validator; | ||
} | ||
const validator = currBlock[validatorType] as ((input: T) => ValidationResult) | undefined; | ||
return typeof validator === "function" ? validator : undefined; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can go in a single line.