File size: 887 Bytes
a8b3f00
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import type { Dispatch, SetStateAction } from 'react'

export enum ValidatedStatus {
  Success = 'success',
  Error = 'error',
  Exceed = 'exceed',
}

export type ValidatedStatusState = {
  status?: ValidatedStatus
  message?: string
}

export type Status = 'add' | 'fail' | 'success'

export type ValidateValue = Record<string, any>

export type ValidateCallback = {
  before: (v?: ValidateValue) => boolean | undefined
  run?: (v?: ValidateValue) => Promise<ValidatedStatusState>
}

export type Form = {
  key: string
  title: string
  placeholder: string
  value?: string
  validate?: ValidateCallback
  handleFocus?: (v: ValidateValue, dispatch: Dispatch<SetStateAction<ValidateValue>>) => void
}

export type KeyFrom = {
  text: string
  link: string
}

export type KeyValidatorProps = {
  type: string
  title: React.ReactNode
  status: Status
  forms: Form[]
  keyFrom: KeyFrom
}