[@@@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." )

setNewCode (fun _ -> (Event.Form.target e)##value ) ) /> setNewDid (fun _ -> (Event.Form.target e)##value ) ) /> setNewRemaining (fun _ -> (Event.Form.target e)##value ) ) />
]
( 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" )> ( List.map (fun (invite : invite) -> ) invites |> Array.of_list |> array )
(string "Code") (string "For") (string "Remaining")
(string invite.code) (string invite.did) (string (string_of_int invite.remaining))
(* 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 ->
(string "edit invite code")

(string ("Code: " ^ invite.code))

setEditDid (fun _ -> (Event.Form.target e)##value ) ) /> setEditRemaining (fun _ -> (Event.Form.target e)##value ) ) />
| 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 ->
(string "delete invite code")

(string ( "Are you sure you want to delete invite code " ^ invite.code ^ "?" ) )

| None -> null )
]