1
- import React , { useCallback , useState } from 'react' ;
1
+ import React from 'react' ;
2
2
import { observer } from 'mobx-react-lite' ;
3
- import * as LIT from 'types/generated/lit-sessions_pb' ;
4
3
import styled from '@emotion/styled' ;
5
4
import { usePrefixedTranslation } from 'hooks' ;
6
- import { MAX_DATE } from 'util/constants' ;
7
5
import { useStore } from 'store' ;
8
6
import { Button , Column , HeaderFour , Row } from 'components/base' ;
9
7
import FormField from 'components/common/FormField' ;
@@ -42,31 +40,11 @@ interface Props {
42
40
43
41
const AddSession : React . FC < Props > = ( { primary } ) => {
44
42
const { l } = usePrefixedTranslation ( 'cmps.connect.AddSession' ) ;
45
- const { sessionStore } = useStore ( ) ;
46
-
47
- const [ label , setLabel ] = useState ( '' ) ;
48
- const [ permissions , setPermissions ] = useState ( 'admin' ) ;
49
- const [ editing , setEditing ] = useState ( false ) ;
50
-
51
- const toggleEditing = useCallback ( ( ) => setEditing ( e => ! e ) , [ ] ) ;
52
- const handleSubmit = useCallback ( async ( ) => {
53
- const sessionType =
54
- permissions === 'admin'
55
- ? LIT . SessionType . TYPE_MACAROON_ADMIN
56
- : LIT . SessionType . TYPE_MACAROON_READONLY ;
57
-
58
- const session = await sessionStore . addSession ( label , sessionType , MAX_DATE , true ) ;
59
-
60
- if ( session ) {
61
- setLabel ( '' ) ;
62
- setEditing ( false ) ;
63
- }
64
- } , [ label , permissions ] ) ;
65
-
43
+ const { addSessionView } = useStore ( ) ;
66
44
const { Wrapper, FormHeader, FormInput, FormSelect } = Styled ;
67
- if ( ! editing ) {
45
+ if ( ! addSessionView . editing ) {
68
46
return (
69
- < PurpleButton tertiary = { ! primary } onClick = { toggleEditing } >
47
+ < PurpleButton tertiary = { ! primary } onClick = { addSessionView . toggleEditing } >
70
48
{ l ( 'create' ) }
71
49
</ PurpleButton >
72
50
) ;
@@ -85,24 +63,33 @@ const AddSession: React.FC<Props> = ({ primary }) => {
85
63
< Row >
86
64
< Column cols = { 6 } >
87
65
< FormField >
88
- < FormInput value = { label } onChange = { setLabel } placeholder = { l ( 'labelHint' ) } />
66
+ < FormInput
67
+ value = { addSessionView . label }
68
+ onChange = { addSessionView . setLabel }
69
+ placeholder = { l ( 'labelHint' ) }
70
+ />
89
71
</ FormField >
90
72
</ Column >
91
73
< Column >
92
74
< FormField >
93
75
< FormSelect
94
- value = { permissions }
95
- onChange = { setPermissions }
76
+ value = { addSessionView . permissionType }
77
+ onChange = { addSessionView . setPermissionType }
96
78
options = { [
97
- { label : 'Admin' , value : 'admin' } ,
98
- { label : 'Read Only' , value : 'read-only' } ,
79
+ { label : l ( 'admin' ) , value : 'admin' } ,
80
+ { label : l ( 'readonly' ) , value : 'read-only' } ,
81
+ { label : l ( 'custom' ) , value : 'custom' } ,
99
82
] }
100
83
/>
101
84
</ FormField >
102
85
</ Column >
103
86
< Column >
104
- < PurpleButton onClick = { handleSubmit } > { l ( 'common.submit' ) } </ PurpleButton >
105
- < Button ghost borderless onClick = { toggleEditing } >
87
+ < PurpleButton onClick = { addSessionView . handleSubmit } >
88
+ { addSessionView . permissionType === 'custom'
89
+ ? l ( 'common.next' )
90
+ : l ( 'common.submit' ) }
91
+ </ PurpleButton >
92
+ < Button ghost borderless onClick = { addSessionView . toggleEditing } >
106
93
{ l ( 'common.cancel' ) }
107
94
</ Button >
108
95
</ Column >
0 commit comments