From fdbcd3d902dfeb969f36492e20b6d9366f39b8b2 Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Wed, 13 Oct 2021 00:44:33 +0100 Subject: [PATCH] Ability to mark org as public while creating in the UI --- chartered-db/src/organisations.rs | 4 +++- chartered-frontend/src/pages/organisations/CreateOrganisation.tsx | 23 +++++++++++++++++++++-- chartered-web/src/endpoints/web_api/organisations/crud.rs | 3 ++- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/chartered-db/src/organisations.rs b/chartered-db/src/organisations.rs index 964f9ab..00953b0 100644 --- a/chartered-db/src/organisations.rs +++ a/chartered-db/src/organisations.rs @@ -99,13 +99,14 @@ conn: ConnectionPool, given_name: String, given_description: String, + given_public: bool, requesting_user_id: i32, ) -> Result<()> { tokio::task::spawn_blocking(move || { let conn = conn.get()?; conn.transaction::<_, crate::Error, _>(|| { - use organisations::dsl::{description, id, name, uuid}; + use organisations::dsl::{description, id, name, uuid, public}; use user_organisation_permissions::dsl::{organisation_id, permissions, user_id}; let generated_uuid = SqlUuid::random(); @@ -115,6 +116,7 @@ uuid.eq(generated_uuid), name.eq(given_name), description.eq(given_description), + public.eq(given_public), )) .execute(&conn)?; diff --git a/chartered-frontend/src/pages/organisations/CreateOrganisation.tsx b/chartered-frontend/src/pages/organisations/CreateOrganisation.tsx index 3b1e9cd..75de76e 100644 --- a/chartered-frontend/src/pages/organisations/CreateOrganisation.tsx +++ a/chartered-frontend/src/pages/organisations/CreateOrganisation.tsx @@ -17,7 +17,10 @@ const [name, setName] = useState(""); const [description, setDescription] = useState(""); + const [publicOrg, setPublicOrg] = useState(false); + console.log(publicOrg); + const createOrganisation = async (evt) => { evt.preventDefault(); @@ -30,7 +33,7 @@ headers: { "Content-Type": "application/json", }, - body: JSON.stringify({ name, description }), + body: JSON.stringify({ name, description, 'public': publicOrg }), }); let json = await res.json(); @@ -67,7 +70,7 @@ className="btn-close" aria-label="Close" onClick={() => setError("")} - > + />
@@ -103,10 +106,24 @@ onChange={(e) => setDescription(e.target.value)} disabled={loading} value={description} + /> +
+ +
+ setPublicOrg(e.target.checked)} + disabled={loading} /> +
-
+