mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 12:37:20 +00:00
introduced auth strategy actions to allow user creation in UI
This commit is contained in:
53
app/src/ui/modules/auth/hooks/use-create-user-modal.ts
Normal file
53
app/src/ui/modules/auth/hooks/use-create-user-modal.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { useApi, useInvalidate } from "ui/client";
|
||||
import { useBkndAuth } from "ui/client/schema/auth/use-bknd-auth";
|
||||
import { routes, useNavigate } from "ui/lib/routes";
|
||||
import { bkndModals } from "ui/modals";
|
||||
|
||||
export function useCreateUserModal() {
|
||||
const api = useApi();
|
||||
const { config } = useBkndAuth();
|
||||
const invalidate = useInvalidate();
|
||||
const [navigate] = useNavigate();
|
||||
|
||||
const open = async () => {
|
||||
const loading = bkndModals.open("overlay", {
|
||||
content: "Loading..."
|
||||
});
|
||||
|
||||
const schema = await api.auth.actionSchema("password", "create");
|
||||
loading.closeAll(); // currently can't close by id...
|
||||
|
||||
bkndModals.open(
|
||||
"form",
|
||||
{
|
||||
schema,
|
||||
uiSchema: {
|
||||
password: {
|
||||
"ui:widget": "password"
|
||||
}
|
||||
},
|
||||
autoCloseAfterSubmit: false,
|
||||
onSubmit: async (data, ctx) => {
|
||||
console.log("submitted:", data, ctx);
|
||||
const res = await api.auth.action("password", "create", data);
|
||||
console.log(res);
|
||||
if (res.ok) {
|
||||
// invalidate all data
|
||||
invalidate();
|
||||
navigate(routes.data.entity.edit(config.entity_name, res.data.id));
|
||||
ctx.close();
|
||||
} else if ("error" in res) {
|
||||
ctx.setError(res.error);
|
||||
} else {
|
||||
ctx.setError("Unknown error");
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
title: "Create User"
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
return { open };
|
||||
}
|
||||
@@ -34,7 +34,11 @@ export function EntityTable2({ entity, select, ...props }: EntityTableProps) {
|
||||
const field = getField(property)!;
|
||||
_value = field.getValue(value, "table");
|
||||
} catch (e) {
|
||||
console.warn("Couldn't render value", { value, property, entity, select, ...props }, e);
|
||||
console.warn(
|
||||
"Couldn't render value",
|
||||
{ value, property, entity, select, columns, ...props },
|
||||
e
|
||||
);
|
||||
}
|
||||
|
||||
return <CellValue value={_value} property={property} />;
|
||||
|
||||
Reference in New Issue
Block a user