@@ -15,7 +15,7 @@ import Select from '../components/Select'
1515import Button from '../components/Button'
1616import List from '../components/List'
1717
18- const Account = ( { token, invites = [ ] , userRole } ) => {
18+ const Account = ( { token, invites = [ ] , user , userRole } ) => {
1919 const [ invitesList , setInvitesList ] = useState ( invites )
2020
2121 const {
@@ -92,14 +92,27 @@ const Account = ({ token, invites = [], userRole }) => {
9292 >
9393 < Text as = "h2" > Invites</ Text >
9494 < form onSubmit = { handleGenerateInvite } >
95- < Box display = "flex" alignItems = "center" >
95+ < Box
96+ display = "flex"
97+ alignItems = "center"
98+ border = "1px solid"
99+ borderColor = "border"
100+ borderRadius = { 1 }
101+ p = { 2 }
102+ pl = { 4 }
103+ >
104+ < Text color = "grey" mr = { 4 } >
105+ { user . remainingInvites } remaining
106+ </ Text >
96107 { userRole === 'admin' && (
97108 < Select name = "role" required mr = { 3 } >
98109 < option value = "user" > Role: user</ option >
99110 < option value = "admin" > Role: admin</ option >
100111 </ Select >
101112 ) }
102- < Button > Generate invite</ Button >
113+ < Button disabled = { user . remainingInvites < 1 } >
114+ Generate invite
115+ </ Button >
103116 </ Box >
104117 </ form >
105118 </ Box >
@@ -126,7 +139,13 @@ const Account = ({ token, invites = [], userRole }) => {
126139 header : 'Valid until' ,
127140 accessor : 'validUntil' ,
128141 cell : ( { value } ) => (
129- < Text > { moment ( value ) . format ( 'HH:mm Do MMM YYYY' ) } </ Text >
142+ < Text
143+ style = { {
144+ textDecoration : value < Date . now ( ) ? 'line-through' : 'none' ,
145+ } }
146+ >
147+ { moment ( value ) . format ( 'HH:mm Do MMM YYYY' ) }
148+ </ Text >
130149 ) ,
131150 gridWidth : '1.2fr' ,
132151 } ,
@@ -148,21 +167,25 @@ const Account = ({ token, invites = [], userRole }) => {
148167 } ,
149168 {
150169 header : 'Copy' ,
151- cell : ( { row } ) => (
152- < Button
153- variant = "secondary"
154- onClick = { ( ) => {
155- copy (
156- `${ location . protocol } //${ location . host } /register?token=${ row . token } `
157- )
158- alert ( 'Invite link copied to clipboard' )
159- } }
160- px = { 1 }
161- py = { 1 }
162- >
163- < Copy size = { 24 } />
164- </ Button >
165- ) ,
170+ cell : ( { row } ) => {
171+ console . log ( row )
172+ return (
173+ < Button
174+ variant = "secondary"
175+ onClick = { ( ) => {
176+ copy (
177+ `${ location . protocol } //${ location . host } /register?token=${ row . token } `
178+ )
179+ alert ( 'Invite link copied to clipboard' )
180+ } }
181+ disabled = { row . claimed }
182+ px = { 1 }
183+ py = { 1 }
184+ >
185+ < Copy size = { 24 } />
186+ </ Button >
187+ )
188+ } ,
166189 rightAlign : true ,
167190 gridWidth : '42px' ,
168191 } ,
@@ -184,6 +207,7 @@ const Account = ({ token, invites = [], userRole }) => {
184207 name = "newPassword"
185208 type = "password"
186209 label = "New password"
210+ autoComplete = "new-password"
187211 mb = { 4 }
188212 required
189213 />
@@ -203,17 +227,24 @@ export const getServerSideProps = async ({ req }) => {
203227 serverRuntimeConfig : { SQ_JWT_SECRET } ,
204228 } = getConfig ( )
205229
206- const { role } = jwt . verify ( token , SQ_JWT_SECRET )
230+ const { role, username } = jwt . verify ( token , SQ_JWT_SECRET )
207231
208232 try {
233+ const userRes = await fetch ( `${ SQ_API_URL } /user/${ username } ` , {
234+ headers : {
235+ 'Content-Type' : 'application/json' ,
236+ Authorization : `Bearer ${ token } ` ,
237+ } ,
238+ } )
239+ const user = await userRes . json ( )
209240 const invitesRes = await fetch ( `${ SQ_API_URL } /account/invites` , {
210241 headers : {
211242 'Content-Type' : 'application/json' ,
212243 Authorization : `Bearer ${ token } ` ,
213244 } ,
214245 } )
215246 const invites = await invitesRes . json ( )
216- return { props : { invites, userRole : role } }
247+ return { props : { invites, user , userRole : role } }
217248 } catch ( e ) {
218249 return { props : { } }
219250 }
0 commit comments