index.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import qrCode from '../../../img/icons8-telegram-app.svg'
  2. import { makeStyles, Button, TextField, MenuItem } from '@material-ui/core'
  3. import Checkbox from '@mui/material/Checkbox';
  4. import FormControlLabel from '@mui/material/FormControlLabel';
  5. import React from 'react';
  6. import { countries } from '../../../helpers/countries'
  7. const useStyles = makeStyles({
  8. container: {
  9. display: 'flex',
  10. alignItems: 'center',
  11. alignContent:'center',
  12. flexDirection: 'column',
  13. width: 350,
  14. margin: '0 auto',
  15. paddingTop: 64,
  16. paddingBottom: 24,
  17. },
  18. picture: {
  19. marginBottom: 16,
  20. paddingLeft: 45
  21. },
  22. title: {
  23. textAlign: 'center',
  24. marginBottom: 16,
  25. },
  26. titleConfirm: {
  27. color: '#b4b4b4',
  28. fontWeight:400
  29. },
  30. buttonQR: {
  31. marginTop: 20,
  32. height: 50,
  33. color: '#5497f0'
  34. },
  35. buttonNext: {
  36. marginTop: 20,
  37. height: 50,
  38. color: '#f8f8f8',
  39. backgroundColor:'#1d74c5',
  40. },
  41. textField: {
  42. marginBottom:20
  43. },
  44. })
  45. interface IAuthorizationForm {
  46. handleIsQR: () => void,
  47. handleIsCheck:(e:React.ChangeEvent<HTMLInputElement>) => void
  48. handleSendCode: () => Promise<void>,
  49. number:string,
  50. setNumber: React.Dispatch<React.SetStateAction<string>>,
  51. country: string,
  52. setCountry: React.Dispatch<React.SetStateAction<string>>,
  53. isChecked: boolean,
  54. isValidCredentials: () => boolean
  55. }
  56. interface ICountry {
  57. name: string,
  58. code: string
  59. }
  60. const Authorization = ({
  61. handleIsQR,
  62. handleIsCheck,
  63. handleSendCode,
  64. number,
  65. setNumber,
  66. country,
  67. setCountry,
  68. isChecked,
  69. isValidCredentials
  70. }: IAuthorizationForm) => {
  71. const classes = useStyles()
  72. const handleTextField = (e: React.ChangeEvent<HTMLInputElement>) => {
  73. const value = e.target.value
  74. const name = e.target.name
  75. switch (name) {
  76. case 'country':
  77. setCountry(value)
  78. const code = countries.find(el => el.name === value)?.code
  79. code&&setNumber(code)
  80. break;
  81. case 'number':
  82. setNumber(value)
  83. break;
  84. default:
  85. break;
  86. }
  87. }
  88. return (
  89. <div className={classes.container}>
  90. <img className={classes.picture} alt="QRCode" src={qrCode} width='270' height='270' />
  91. <h2 className={classes.title}>Telegram</h2>
  92. <h4 className={classes.title + ' ' + classes.titleConfirm}>
  93. Please confirm your country code and enter your phone number.
  94. </h4>
  95. <TextField
  96. id="country"
  97. name='country'
  98. label="Country"
  99. fullWidth
  100. variant='outlined'
  101. defaultValue=''
  102. select
  103. className={classes.textField}
  104. onChange={handleTextField}
  105. >
  106. {countries.map(({name}: ICountry) => (
  107. <MenuItem value={name} key={name}>
  108. {name}
  109. </MenuItem>
  110. ))}
  111. </TextField>
  112. <TextField
  113. id="number"
  114. name='number'
  115. label="Your phone number"
  116. value={number}
  117. fullWidth
  118. variant='outlined'
  119. onChange={handleTextField}
  120. />
  121. <FormControlLabel
  122. label="Keep me signed in"
  123. control={<Checkbox
  124. checked={isChecked}
  125. onChange={handleIsCheck}
  126. inputProps={{ 'aria-label': 'controlled' }}
  127. />}
  128. />
  129. {isValidCredentials() &&
  130. <Button
  131. onClick={handleSendCode}
  132. className={classes.buttonNext}
  133. color='primary'
  134. variant="contained"
  135. fullWidth>
  136. NEXT
  137. </Button>}
  138. <Button
  139. onClick={handleIsQR}
  140. className={classes.buttonQR}
  141. variant="text"
  142. color="default"
  143. fullWidth>
  144. LOG IN BY QR CODE
  145. </Button>
  146. </div>
  147. );
  148. };
  149. export default Authorization;