Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.66 KB | None | 0 0
  1. import React, { useState } from 'react'
  2. import styled, { css, FlattenSimpleInterpolation } from 'styled-components'
  3. import { values } from 'mobx'
  4. import { Popover } from 'antd'
  5. import { Button as CustomButton } from '@elements/form-controls/Button'
  6. import SelectDisplayMenus from './modals/SelectDisplayMenus'
  7. import ItemDetails from './ItemDetails'
  8. import Customize from './Icons/Customize.svg'
  9. import CustomizeSelected from './Icons/CustomizeSelected.svg'
  10.  
  11. const BottomPartContainer = styled.div`
  12. height: 46px;
  13. font-weight: 500;
  14. font-size: 14px;
  15. line-height: 20px;
  16. text-align: center;
  17. letter-spacing: 0.888889px;
  18. color: #3F3F52;
  19. margin: 72px 0 216px 0;
  20. `
  21.  
  22. const Button = styled(CustomButton)`
  23. `
  24.  
  25. const BoxWithWidth = styled.div`
  26. width= 228px;
  27. `
  28.  
  29. const Container = styled.div`
  30. font-family: Montserrat;
  31. font-style: normal;
  32. width: 1148px;
  33. background: #FFFFFF;
  34. border: 1px solid #FEF2F0;
  35. box-sizing: border-box;
  36. box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.08);
  37. padding: 0 0 21px 32px;
  38. `
  39.  
  40. const ControlsHolder = styled.div`
  41. width: 501px;
  42. height: 44px;
  43. border: 1px solid #E7E4E3;
  44. box-sizing: border-box;
  45. display: flex;
  46. margin: 24px 0 25px 0;
  47. `
  48.  
  49. const CreateButton = styled(Button).attrs((props) => ({
  50. type: props.type || 'info',
  51. }))`
  52. background: #35BF7D;
  53. font-weight: 500;
  54. font-size: 14px;
  55. line-height: 16px;
  56. display: flex;
  57. align-items: center;
  58. justify-content: center;
  59. letter-spacing: 1px;
  60. color: #FFFFFF;
  61. width: 190px;
  62. height: 44px;
  63. &:hover {
  64. background: #299b62;
  65. }
  66. `
  67.  
  68. const DrawerContainer = styled.div<{ open: boolean }>`
  69. width: 100%;
  70. transition: 0.3s;
  71. ${(props): FlattenSimpleInterpolation => props.open && css`
  72. width: calc(100% - 540px);
  73. border: 1px solid #DFDFDF;
  74. padding: 0 21px;
  75. `}
  76. `
  77.  
  78. const Heading = styled.h1`
  79. height: 20px;
  80. font-weight: 600;
  81. font-size: 24px;
  82. line-height: 20px;
  83. color: #3F3F52;
  84. margin: 36px 0 29px 0;
  85. `
  86.  
  87. const ItemsCountParagraph = styled.p`
  88. height: 20px;
  89. font-weight: 600;
  90. font-size: 14px;
  91. line-height: 20px;
  92. letter-spacing: 0.888889px;
  93. color: #3F3F52;
  94. margin-bottom: 78px;
  95. `
  96.  
  97. const ItemSeparator = styled.div`
  98. display: flex;
  99. justify-content: space-between;
  100. `
  101.  
  102. const MenuRow = styled.div`
  103. font-weight: 500;
  104. font-size: 16px;
  105. line-height: 1px;
  106. letter-spacing: 0.888889px;
  107. color: #3F3F52;
  108. opacity: 0.7;
  109. display: flex;
  110. border-bottom: 1px solid #e7e4e3;
  111. width: 100%;
  112. & >div {
  113. padding: 0 30px;
  114. display: flex;
  115. align-items: center;
  116. height: 70px;
  117. &:first-child {
  118. width: 33%;
  119. }
  120. &:nth-child(2) {
  121. width: 17%;
  122. }
  123. &:last-child {
  124. width: 50%;
  125. }
  126. }
  127. `
  128.  
  129. const MenuRowSelected = styled.div`
  130. background: #34C47C;
  131. font-size: 16px;
  132. line-height: 1px;
  133. letter-spacing: 0.888889px;
  134. color: #FFFFFF;
  135. display: flex;
  136. border-bottom: 1px solid #e7e4e3;
  137. width: 100%;
  138. & >div {
  139. padding: 0 30px;
  140. display: flex;
  141. align-items: center;
  142. height: 70px;
  143. &:first-child {
  144. width: 40%;
  145. }
  146. &:nth-child(2) {
  147. width: 20%;
  148. }
  149. &:last-child {
  150. width: 40%;
  151. }
  152. }
  153. `
  154.  
  155. const MenuRowShrinked = styled(MenuRow)`
  156. & >div {
  157. &:first-child {
  158. width: 40%;
  159. }
  160. &:nth-child(2) {
  161. width: 20%;
  162. }
  163. &:last-child {
  164. width: 40%;
  165. }
  166. }
  167. `
  168.  
  169. const MenuTableHeader = styled(MenuRow)`
  170. font-size: 12px;
  171. line-height: 16px;
  172. `
  173.  
  174. const MenuTableHeaderShrinked = styled(MenuRowShrinked)`
  175. font-size: 12px;
  176. line-height: 16px;
  177. `
  178.  
  179. const SearchInput = styled.input`
  180. width: 311px;
  181. height: 44px;
  182. background: #FFFFFF;
  183. border: 1px solid #E7E4E3;
  184. box-sizing: border-box;
  185. font-weight: 500;
  186. font-size: 14px;
  187. line-height: 16px;
  188. display: flex;
  189. align-items: flex-end;
  190. color: #6C6C6C;
  191. padding-left: 13px;
  192. `
  193.  
  194. const SpanWithPadding = styled.span`
  195. padding-left: 180px;
  196. `
  197.  
  198. const SpanWithPaddingShrinked = styled.span`
  199. padding-left: 80px;
  200. `
  201.  
  202. const TextParagraph = styled.p`
  203. height: 23px;
  204. font-weight: 500;
  205. font-size: 14px;
  206. line-height: 20px;
  207. text-align: center;
  208. letter-spacing: 0.888889px;
  209. color: #3F3F52;
  210. margin-bottom: 0;
  211. `
  212.  
  213. const PopoverContent = (props: { sandbox: jc.Sandbox }): React.ReactElement<null> =>
  214. <SelectDisplayMenus sandbox={props.sandbox} />
  215.  
  216. export default (props: { sandbox: jc.Sandbox }): JSX.Element => {
  217. const [selectedItemId, select] = useState(-1)
  218. const changeSelection = (id: number): void => select(id)
  219.  
  220. const [isOpen, open] = useState(false)
  221. const ItemDetailsColumn = selectedItemId !== -1 ? <ItemDetails sandbox={props.sandbox} /> : ''
  222.  
  223. const items = values(props.sandbox.globalData.itemStore.items)
  224. const ItemsList = items.map((i) =>
  225. <MenuRow onClick={(): void => { open(true); changeSelection(i.id); }}>
  226. <div>{i.name}</div>
  227. <div>$ {i.price.toFixed(2)}</div>
  228. <ItemSeparator>
  229. {/* TODO: Remove this hardcoded value when the meaning is clear */}
  230. <SpanWithPadding>4</SpanWithPadding>
  231. <Popover trigger={'hover'} placement={'bottom'} content={<PopoverContent sandbox={props.sandbox} />}>
  232. <Customize />
  233. </Popover>
  234. </ItemSeparator>
  235. </MenuRow>)
  236.  
  237. const ItemsListShrinked = items.map((i) => i.id === selectedItemId ?
  238. (<MenuRowSelected>
  239. <div>{i.name}</div>
  240. <div>$ {i.price.toFixed(2)}</div>
  241. <ItemSeparator>
  242. {/* TODO: Remove this hardcoded value when the meaning is clear */}
  243. <SpanWithPaddingShrinked>4</SpanWithPaddingShrinked>
  244. <Popover trigger={'hover'} placement={'bottom'} content={<PopoverContent sandbox={props.sandbox} />}>
  245. <CustomizeSelected />
  246. </Popover>
  247. </ItemSeparator>
  248. </MenuRowSelected>)
  249. :
  250. (<MenuRowShrinked onClick={(): void => { open(true); changeSelection(i.id); }}>
  251. <div>{i.name}</div>
  252. <div>$ {i.price.toFixed(2)}</div>
  253. <ItemSeparator>
  254. {/* TODO: Remove this hardcoded value when the meaning is clear */}
  255. <SpanWithPaddingShrinked>4</SpanWithPaddingShrinked>
  256. <Popover trigger={'hover'} placement={'bottom'} content={<PopoverContent sandbox={props.sandbox} />}>
  257. <Customize />
  258. </Popover>
  259. </ItemSeparator>
  260. </MenuRowShrinked>))
  261.  
  262. const Content = values(props.sandbox.globalData.itemStore.items).length === 0 ? (
  263. <BottomPartContainer>
  264. <TextParagraph>You have no items added.</TextParagraph>
  265. <TextParagraph>Click on "<strong>Create New Item</strong> to get started</TextParagraph>
  266. <Button
  267. css={'width: 190px; height: 44px; background: #F0703D; margin-top: 20px;'}
  268. type={'primary'}
  269. onClick={(): void => props.sandbox.redirect('/item/create')}
  270. >
  271. Create new Item
  272. </Button>
  273. </BottomPartContainer>
  274. ) : (
  275. <div>
  276. {selectedItemId === - 1 ? ItemsList : ItemsListShrinked}
  277. </div>
  278. )
  279.  
  280. return (
  281. <Container>
  282. <Heading>Create new Item</Heading>
  283. <DrawerContainer open={isOpen}>
  284. <ControlsHolder>
  285. <SearchInput placeholder={'Search items'} />
  286. <CreateButton onClick={(): void => props.sandbox.redirect('/item/create')}>Create new Item</CreateButton>
  287. </ControlsHolder>
  288. <ItemsCountParagraph>Total items {items.length}</ItemsCountParagraph>
  289. {selectedItemId === -1 ?
  290. <MenuTableHeader>
  291. <div>ITEM NAME</div>
  292. <div>PRICE</div>
  293. <BoxWithWidth>NUMBER OF BREEZE MENUS DISPLAYING ITEM</BoxWithWidth>
  294. </MenuTableHeader>
  295. :
  296. <MenuTableHeaderShrinked>
  297. <div>ITEM NAME</div>
  298. <div>PRICE</div>
  299. <div>IN MENUS</div>
  300. </MenuTableHeaderShrinked>
  301. }
  302. {Content}
  303. </DrawerContainer>
  304.  
  305. {ItemDetailsColumn}
  306. </Container>
  307. )
  308. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement