@react.component let make = () => { module Proto = { type t = HTTP | HTTPS let default = HTTPS let make = str => switch(str) { | "http" => HTTP | _ => default } let make2 = mayStr => switch(mayStr) { | Some(str) => make(str) | None => default } let toStr = p => switch(p) { | HTTP => "http" | HTTPS => "https" } let isTls = p => p == HTTPS } module UrlStyle = { type t = VHOST | PATH let default = PATH let make = str => switch(str) { | "vhost" => VHOST | _ => default } let make2 = mayStr => switch(mayStr) { | Some(str) => make(str) | None => default } let toStr = u => switch(u) { | PATH => "path" | VHOST => "vhost" } let isPathStyle = u => u == PATH } module LocalKV = { open Dom let get = (key) => Storage2.localStorage -> Storage2.getItem(key) let set = (key, value) => Storage2.localStorage -> Storage2.setItem(key, value) } module Config = { open Belt type t = { protocol: Proto.t, url: UrlStyle.t, endpoint: string, region: string, keyId: string, secretKey: string, } let make = () => { protocol: "conf_protocol" -> LocalKV.get -> Proto.make2, url: "conf_url" -> LocalKV.get -> UrlStyle.make2, endpoint: "conf_endpoint" -> LocalKV.get -> Option.getWithDefault("garage.deuxfleurs.fr"), region: "conf_region" -> LocalKV.get -> Option.getWithDefault("garage"), keyId: "conf_keyid" -> LocalKV.get -> Option.getWithDefault(""), secretKey: "conf_secretkey" -> LocalKV.get -> Option.getWithDefault(""), } let build = c => { { S3.endpoint: Some({ protocol: c.protocol -> Proto.toStr, hostname: c.endpoint, path: "/" }), credentials: Some({ accessKeyId: c.keyId, secretAccessKey: c.secretKey, }), tls: Some(c.protocol -> Proto.isTls), forcePathStyle: Some(c.url -> UrlStyle.isPathStyle), region: Some(c.region), } } } let (config, updateConfig) = React.useState(_ => Config.make()); let login = _ => { Js.log(config -> Config.build) } let setProtocol = evt => { let value = ReactEvent.Form.target(evt)["value"] -> Proto.make updateConfig(c => {...c, protocol: value}) } let setEndpoint = evt => { let value = (ReactEvent.Form.target(evt)["value"]) updateConfig(c => {...c, endpoint: value }) } let setRegion = evt => { let value = (ReactEvent.Form.target(evt)["value"]) updateConfig(c => {...c, region: value }) } let setUrlStyle = evt => { let value = ReactEvent.Form.target(evt)["value"] -> UrlStyle.make updateConfig(c => {...c, url: value }) } let setKeyId = evt => { let value = (ReactEvent.Form.target(evt)["value"]) updateConfig(c => {...c, keyId: value }) } let setSecretKey = evt => { let value = (ReactEvent.Form.target(evt)["value"]) updateConfig(c => {...c, secretKey: value }) }
{ "Configuration"->React.string }
{ `Réseau` -> React.string }
{ "Authentification"->React.string }
}