MkInfo.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { makeStyles } from '@material-ui/core/styles';
  4. import { Grid, Box, Typography, Button } from '@material-ui/core';
  5. const useStyles = makeStyles((theme) => ({
  6. root: {
  7. width: '100%',
  8. },
  9. paper: {
  10. width: '100%',
  11. marginBottom: theme.spacing(2),
  12. },
  13. table: {
  14. minWidth: 750,
  15. },
  16. visuallyHidden: {
  17. border: 0,
  18. clip: 'rect(0 0 0 0)',
  19. height: 1,
  20. margin: -1,
  21. overflow: 'hidden',
  22. padding: 0,
  23. position: 'absolute',
  24. top: 20,
  25. width: 1,
  26. },
  27. underline: {
  28. "&&&:before": {
  29. borderBottom: "none"
  30. },
  31. "&&:after": {
  32. borderBottom: "none"
  33. }
  34. }, button: {
  35. color: 'white',
  36. width: 150,
  37. height: 55
  38. },
  39. closeButton: {
  40. position: 'absolute',
  41. right: theme.spacing(1),
  42. top: theme.spacing(1),
  43. color: theme.palette.grey[500],
  44. },
  45. headText: {
  46. fontSize: 14,
  47. float: "left",
  48. color: theme.palette.primary.main,
  49. fontWeight: "bold"
  50. },
  51. }));
  52. function getDataString(data, fieldName) {
  53. return data[fieldName];
  54. }
  55. function MkInfo(props) {
  56. const classes = useStyles();
  57. const {
  58. infoData,
  59. displayFields,
  60. isNew = false,
  61. isEditable,
  62. currentTabName,
  63. actions } = props;
  64. const [editable, setEditable] = React.useState(isEditable !== undefined ? isEditable : true);
  65. // const [data, setData] = React.useState({});
  66. const handleEdit = () => {
  67. setEditable(false)
  68. }
  69. // const handleUpdateData = (data) => {
  70. // console.log('handle update date:', data);
  71. // setData(data);
  72. // }
  73. return (
  74. <div className={classes.root}>
  75. {isNew ?
  76. <Grid container style={{ marginTop: '30px' }}>
  77. <Grid item xs={12} sm={7}>
  78. {/* <MkForm
  79. updateData={infoData}
  80. fields={displayFields}
  81. isNew={isNew}
  82. onDataCallback={(d) => handleUpdateData(d)}
  83. ></MkForm> */}
  84. </Grid>
  85. </Grid> : <Grid container style={{ marginTop: '30px' }}>
  86. <Grid item xs={12} sm={7}>
  87. {!editable ?
  88. // <MkForm
  89. // fields={displayFields}
  90. // isNew={isNew}
  91. // updateData={infoData}
  92. // onDataCallback={(d) => handleUpdateData(d)}
  93. // ></MkForm>
  94. <div/>
  95. :
  96. displayFields.map((d, i) => {
  97. return (<Grid container key={i}>
  98. <Grid item xs={12} style={{ display: 'flex', alignItems: 'center', marginBottom: '10px' }}>
  99. <Grid item xs={12} sm={5}>
  100. <Box style={{ width: '250px' }}>
  101. <Typography style={{ paddingRight: '30px', color: 'grey' }}>{d.label}</Typography>
  102. </Box>
  103. </Grid>
  104. <Grid item xs={12} sm={7}>
  105. {d.type === 'photo' ?
  106. <img/>
  107. // <img src={infoData['photo_url']} style={{ width: '120px', height: '120px', border: '1px solid grey' }}></img>
  108. :
  109. <Typography style={{ paddingRight: '30px' }}>{infoData !== undefined ? getDataString(infoData, d.fieldName) : ''}</Typography>}
  110. </Grid>
  111. </Grid>
  112. </Grid>);
  113. })}
  114. </Grid>
  115. <Grid item xs={12} sm={7}>
  116. <Grid
  117. container
  118. direction="row"
  119. alignItems="flex-end">
  120. {actions.map((a, i) => {
  121. if (currentTabName === 'account') {
  122. if (infoData.status === 'invited') {
  123. return <Box>
  124. <Button style={{ color: 'white', backgroundColor: 'grey', float: 'right', marginLeft: '10px' }}
  125. // onClick={() => a.callback(data)}
  126. >{a.label}</Button>
  127. </Box>;
  128. }
  129. if (infoData.status === 'joined') {
  130. return <Box>
  131. <Button style={{ color: 'white', backgroundColor: 'grey', float: 'right', marginLeft: '10px' }}
  132. // onClick={() => a.callback(data)}
  133. >{a.label}</Button>
  134. </Box>;
  135. }
  136. if (infoData.status === 'disabled') {
  137. return <Box>
  138. <Button style={{ color: 'white', backgroundColor: 'grey', float: 'right', marginLeft: '10px' }}
  139. // onClick={() => a.callback(data)}
  140. >{a.label}</Button>
  141. </Box>;
  142. }
  143. if (infoData.status === 'requested') {
  144. if (editable) {
  145. return <Box>
  146. <Button style={{ marginLeft: '10px' }}
  147. onClick={handleEdit}
  148. >{a.icon}{a.label}</Button>
  149. </Box>;
  150. } else {
  151. return <Box>
  152. <Button style={{ color: 'white', backgroundColor: 'grey', float: 'right', marginLeft: '10px' }}
  153. // onClick={() => a.callback(data)}
  154. >{a.label}</Button>
  155. </Box>;
  156. }
  157. }
  158. } else {
  159. if (editable) {
  160. if (a.action_type === 'edit') {
  161. console.log('type: ', a.action_type, 'editable: ', editable);
  162. return <Box>
  163. <Button style={{ marginLeft: '10px' }}
  164. onClick={handleEdit}
  165. >{a.icon}{a.label}</Button>
  166. </Box>
  167. }
  168. if (a.action_type === 'delete') {
  169. return <Box>
  170. <Button style={{ float: 'right', marginLeft: '10px' }}
  171. // onClick={() => a.callback(data)}
  172. >{a.icon}{a.label}</Button>
  173. </Box>
  174. }
  175. } else {
  176. if (a.action_type === 'save') {
  177. return <Box>
  178. <Button style={{ marginLeft: '10px' }}
  179. // onClick={() => a.callback(data)}
  180. >{a.icon}{a.label}</Button>
  181. </Box>
  182. }
  183. if (a.action_type === 'cancel') {
  184. return <Box>
  185. <Button style={{ float: 'right', marginLeft: '10px' }}
  186. // onClick={() => a.callback(data)}
  187. >{a.icon}{a.label}</Button>
  188. </Box>
  189. }
  190. }
  191. }
  192. })}
  193. </Grid>
  194. </Grid>
  195. </Grid>}
  196. </div >
  197. );
  198. }
  199. MkInfo.propTypes = {
  200. history: PropTypes.object,
  201. infoData: PropTypes.object,
  202. displayFields: PropTypes.array,
  203. isNew: PropTypes.bool,
  204. isEditable: PropTypes.bool,
  205. actions: PropTypes.any
  206. };
  207. export default (MkInfo);