-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ajuste no useError e emissão dos errors de mídia e texto. (#573)
* chore: adjust useError and emit ccorrectly errors * fix: fix useError test and ComposerEditor test * chore: adjust composer editor and input media composer error emiter * chore: remove media errors in use error * chore: refactor validators type * fix: fix name add error function in main composer * fix: fix tabber errors from validator text * fix: pretier fix * fix: imput media test fixed * fix: accumulation of errors in ladle * chore: implements text error validator * chore: remove error destructuring * fix: function renderInputMediaGroup name fixed * fix: fix input media group * fix: composer editor * fix: code style * fix: code style * refactor: refactor media functions * chore: create PostModeInputMediaGroup component * fix: add hasPostMode variable in MainComposerBase component * fix: remove eslint_report.json * fix: prettier fix * fix: prettier fix
- Loading branch information
Showing
21 changed files
with
441 additions
and
227 deletions.
There are no files selected for viewing
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
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
36 changes: 14 additions & 22 deletions
36
src/components/MainComposer/components/ComposerEditor/ComposerEditor.types.ts
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,31 +1,23 @@ | ||
import { ChangeEvent, PropsWithChildren } from 'react'; | ||
|
||
import { PostMode } from '~services/api/social-media/social-media.types'; | ||
import { MainComposerChildrens } from '../MainComposerBase/MainComposerBase.type'; | ||
|
||
export type TInputChange = (newText: string) => void; | ||
export type TInputPostChange = ( | ||
event: ChangeEvent<HTMLTextAreaElement> | ||
) => void; | ||
export type InputChange = (event: ChangeEvent<HTMLTextAreaElement>) => void; | ||
|
||
export type ComposerEditorProps = PropsWithChildren<{ | ||
accountId?: string; | ||
currentMaxLimit?: number; | ||
onChange?: TInputChange; | ||
onChangePost?: TInputPostChange; | ||
onError?: (error: ErrorMapText) => void; | ||
postMode?: PostMode; | ||
value?: string; | ||
}>; | ||
|
||
export type ErrorText = { | ||
accountId: string | undefined; | ||
message: string; | ||
postModeId: string | undefined; | ||
}; | ||
|
||
export type ErrorMapText = Record<string, ErrorText[]>; | ||
export type ComposerEditorProps = MainComposerChildrens & | ||
PropsWithChildren<{ | ||
currentMaxLimit?: number; | ||
onChange?: InputChange; | ||
value?: string; | ||
}>; | ||
|
||
export type HigherLimitSocial = { | ||
limit: number; | ||
socialMediaId: string; | ||
}; | ||
|
||
export enum TEXT_ERRORS { | ||
MAX_LENGTH_EXCEED = 1, | ||
} | ||
|
||
export type TextErrorMap = Partial<Record<TEXT_ERRORS, string>>; |
36 changes: 36 additions & 0 deletions
36
src/components/MainComposer/components/ComposerEditor/utils/textValidator/textValidator.ts
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { TextValidators } from './textValidators'; | ||
|
||
import { ComposerEditorProps, TEXT_ERRORS } from '../../ComposerEditor.types'; | ||
import { | ||
Payload, | ||
Validator, | ||
ValidatorError, | ||
Validators, | ||
} from './textValidator.types'; | ||
|
||
export const textValidator = ({ | ||
text, | ||
validatorRules, | ||
}: Validator): Validators => { | ||
const textValidators = new TextValidators(text); | ||
|
||
return { | ||
textLength: (props: ComposerEditorProps): ValidatorError => { | ||
const isTextTooLong = !textValidators.textLength( | ||
validatorRules.maxLength | ||
); | ||
|
||
const payload: Payload = { | ||
type: TEXT_ERRORS.MAX_LENGTH_EXCEED, | ||
}; | ||
if (isTextTooLong && props.accountId && props.postMode) { | ||
payload.error = { | ||
accountId: props.accountId, | ||
message: `Account ${props.accountId} on ${props.postMode.id} type of post overflowed the character limit`, | ||
postModeId: props.postMode.id, | ||
}; | ||
} | ||
return payload; | ||
}, | ||
}; | ||
}; |
27 changes: 27 additions & 0 deletions
27
...ponents/MainComposer/components/ComposerEditor/utils/textValidator/textValidator.types.ts
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { TextValidator } from '~services/api/social-media/social-media.types'; | ||
|
||
import { TextValidators } from './textValidators'; | ||
|
||
import { Error } from '~components/MainComposer/components/MainComposerBase/MainComposerBase.type'; | ||
|
||
import { ComposerEditorProps, TEXT_ERRORS } from '../../ComposerEditor.types'; | ||
|
||
export type Validators = Record< | ||
keyof typeof TextValidators.prototype, | ||
(props: ComposerEditorProps) => ValidatorError | ||
>; | ||
|
||
export type Validator = { | ||
text: string; | ||
validatorRules: TextValidator; | ||
}; | ||
|
||
export type ValidatorError = { | ||
error?: Error; | ||
type: TEXT_ERRORS; | ||
}; | ||
|
||
export type Payload = { | ||
error?: Error; | ||
type: TEXT_ERRORS; | ||
}; |
Oops, something went wrong.