[@@@ocaml.warning "-26-27"]
open Melange_json.Primitives
open React
type invite = {code: string; did: string; remaining: int} [@@deriving json]
type props =
{ invites: invite list
; csrf_token: string
; error: string option [@default None]
; success: string option [@default None] }
[@@deriving json]
let[@react.component] make
~props:({invites; csrf_token; error; success} : props) () =
(* create invite modal state *)
let createModalOpen, setCreateModalOpen = useState (fun () -> false) in
let newCode, setNewCode = useState (fun () -> "") in
let newDid, setNewDid = useState (fun () -> "") in
let newRemaining, setNewRemaining = useState (fun () -> "1") in
(* edit modal state *)
let editModalFor, setEditModalFor =
useState (fun () -> (None : invite option))
in
let editDid, setEditDid = useState (fun () -> "admin") in
let editRemaining, setEditRemaining = useState (fun () -> "") in
(* delete confirmation state *)
let deleteConfirmFor, setDeleteConfirmFor =
useState (fun () -> (None : invite option))
in
(string "invite codes")
(string "Manage invite codes for new account registration.")
(string "create invite code")
)>
[%browser_only
fun () ->
let module Aria = ReactAria in
setCreateModalOpen (fun _ -> o))>
(string "create invite code")
(string
"Create a new invite code for user registration." )
]
( match error with
| Some err ->
(string err)
| None ->
null )
( match success with
| Some msg ->
(string msg)
| None ->
null )
0 then "overflow-x-auto"
else "overflow-x-hidden" )>
(string "Code")
(string "For")
(string "Remaining")
( List.map
(fun (invite : invite) ->
(string invite.code)
(string invite.did)
(string (string_of_int invite.remaining))
)
invites
|> Array.of_list |> array )
(* edit modal *)
[%browser_only
fun () ->
let module Aria = ReactAria in
None)
onOpenChange=(fun o ->
if not o then setEditModalFor (fun _ -> None) )>
( match editModalFor with
| Some invite ->
| None ->
null )
]
(* delete confirmation modal *)
[%browser_only
fun () ->
let module Aria = ReactAria in
None)
onOpenChange=(fun o ->
if not o then setDeleteConfirmFor (fun _ -> None) )>
( match deleteConfirmFor with
| Some invite ->
| None ->
null )
]