UNPKG

aau-auth-kit-ui

Version:

Plug & play shadcn/ui components for aau-auth-kit with Next.js integration

146 lines (120 loc) 6.84 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }"use client"; var _chunkCKHGUCXTcjs = require('./chunk-CKHGUCXT.cjs'); // src/components/organization/invitation/invite-member-dialog.tsx var _zod = require('@hookform/resolvers/zod'); var _react = require('react'); var _reacthookform = require('react-hook-form'); var _zod3 = require('zod'); var z = _interopRequireWildcard(_zod3); var _jsxruntime = require('react/jsx-runtime'); var inviteFormSchema = z.object({ email: z.string().email({ message: "Please enter a valid email address" }), role: z.string().min(1, { message: "Role is required" }) }); function InviteMemberDialog({ open, onOpenChange, roles }) { const { authClient, toast } = _react.useContext.call(void 0, _chunkCKHGUCXTcjs.AuthUIContext); const { data: org } = authClient.useActiveOrganization(); const form = _reacthookform.useForm.call(void 0, { resolver: _zod.zodResolver.call(void 0, inviteFormSchema), defaultValues: { email: "", role: "" } }); const onSubmit = async (data) => { await _optionalChain([authClient, 'optionalAccess', _ => _.organization, 'optionalAccess', _2 => _2.inviteMember, 'call', _3 => _3( { email: _optionalChain([data, 'optionalAccess', _4 => _4.email]), role: _optionalChain([data, 'optionalAccess', _5 => _5.role]) }, { onSuccess(context) { toast({ message: `${_optionalChain([data, 'optionalAccess', _6 => _6.email])} has been invited to ${_optionalChain([org, 'optionalAccess', _7 => _7.name])}` }); form.reset(); onOpenChange(); }, onError(context) { toast({ message: context.error.message, variant: "error" }); } } )]); }; const isSubmitting = form.formState.isSubmitting; return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkCKHGUCXTcjs.Dialog, { open, onOpenChange, children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkCKHGUCXTcjs.DialogContent, { className: "sm:max-w-[425px]", children: [ /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkCKHGUCXTcjs.DialogHeader, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkCKHGUCXTcjs.DialogTitle, { children: "Invite Member" }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkCKHGUCXTcjs.DialogDescription, { children: "Invite a new member to your organization. They will receive an email with instructions to join." }) ] }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkCKHGUCXTcjs.Form, { ...form, children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "form", { onSubmit: form.handleSubmit(onSubmit), className: "space-y-4", children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkCKHGUCXTcjs.FormField, { control: form.control, name: "email", render: ({ field }) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkCKHGUCXTcjs.FormItem, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkCKHGUCXTcjs.FormLabel, { children: "Email" }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkCKHGUCXTcjs.FormControl, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkCKHGUCXTcjs.Input, { placeholder: "member@example.com", ...field, disabled: isSubmitting } ) }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkCKHGUCXTcjs.FormMessage, {}) ] }) } ), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkCKHGUCXTcjs.FormField, { control: form.control, name: "role", render: ({ field }) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkCKHGUCXTcjs.FormItem, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkCKHGUCXTcjs.FormLabel, { children: "Role" }), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkCKHGUCXTcjs.Select, { onValueChange: field.onChange, value: field.value, defaultValue: field.value, disabled: isSubmitting, children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkCKHGUCXTcjs.FormControl, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkCKHGUCXTcjs.SelectTrigger, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkCKHGUCXTcjs.SelectValue, { placeholder: "Select a role" }) }) }), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkCKHGUCXTcjs.SelectContent, { children: _optionalChain([roles, 'optionalAccess', _8 => _8.map, 'call', _9 => _9((role) => { return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkCKHGUCXTcjs.SelectItem, { value: _optionalChain([role, 'optionalAccess', _10 => _10.key]), children: _optionalChain([role, 'optionalAccess', _11 => _11.value]) }, role.key); })]) }) ] } ), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkCKHGUCXTcjs.FormMessage, {}) ] }) } ), /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _chunkCKHGUCXTcjs.DialogFooter, { children: [ /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkCKHGUCXTcjs.Button, { type: "button", variant: "outline", onClick: () => onOpenChange(), disabled: isSubmitting, children: "Cancel" } ), /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkCKHGUCXTcjs.Button, { type: "submit", disabled: isSubmitting, children: isSubmitting ? "Inviting..." : "Invite Member" }) ] }) ] }) }) ] }) }); } var invite_member_dialog_default = InviteMemberDialog; exports.default = invite_member_dialog_default; module.exports = exports.default;