Skip to content

armgit / papra

Public Imported from GitHub
0

The minimalistic document archiving platform.

refactor(organizations): refined organization creation flow (#13)

Corentin THOMASSETcfac6ebf5488
diff --git a/apps/papra-client/package.json b/apps/papra-client/package.json
index a92a2469..488192e9 100644
--- a/apps/papra-client/package.json
+++ b/apps/papra-client/package.json
@@ -30,6 +30,7 @@
"dependencies": {
"@corentinth/chisels": "^1.0.2",
"@kobalte/core": "^0.13.4",
+ "@modular-forms/solid": "^0.25.0",
"@pdfslick/solid": "^2.0.0",
"@solid-primitives/i18n": "^2.1.1",
"@solid-primitives/storage": "^4.2.1",
@@ -50,6 +51,7 @@
"ts-pattern": "^5.5.0",
"unocss-preset-animations": "^1.1.0",
"uqr": "^0.1.2",
+ "valibot": "1.0.0-beta.10",
"zod": "^3.23.8"
},
"devDependencies": {
diff --git a/apps/papra-client/src/modules/auth/pages/generic-auth.page.tsx b/apps/papra-client/src/modules/auth/pages/generic-auth.page.tsx
index b7aa2ce1..88804103 100644
--- a/apps/papra-client/src/modules/auth/pages/generic-auth.page.tsx
+++ b/apps/papra-client/src/modules/auth/pages/generic-auth.page.tsx
@@ -1,13 +1,13 @@
import type { Component, ParentComponent } from 'solid-js';
import { config } from '@/modules/config/config';
-import { createForm } from '@/modules/shared/form/form';
+import { createForm } from '@/modules/shared/form/form-legacy';
import { isHttpErrorWithStatusCode } from '@/modules/shared/http/http-errors';
import { useAsyncState } from '@/modules/shared/signals/async-state';
import { cn } from '@/modules/shared/style/cn';
import { createVitrineUrl } from '@/modules/shared/utils/urls';
import { Button } from '@/modules/ui/components/button';
import { Separator } from '@/modules/ui/components/separator';
-import { toast } from '@/modules/ui/components/sonner';
+import { createToast } from '@/modules/ui/components/sonner';
import { TextField, TextFieldLabel, TextFieldRoot } from '@/modules/ui/components/textfield';
import { A, useNavigate } from '@solidjs/router';
import { createSignal, For, Show } from 'solid-js';
@@ -61,11 +61,11 @@ export const MagicLinkLinkForm: Component = () => {
onError(({ error }) => {
if (isHttpErrorWithStatusCode({ error, statusCode: 429 })) {
- toast.error('Too many magic link requests. Please try again later.');
+ createToast({ type: 'error', message: 'Too many magic link requests. Please try again later.' });
return;
}
- toast.error('An error occurred while requesting the magic link. Please try again later.');
+ createToast({ type: 'error', message: 'An error occurred while requesting the magic link. Please try again later.' });
});
return (
diff --git a/apps/papra-client/src/modules/documents/components/document-management-dropdown.component.tsx b/apps/papra-client/src/modules/documents/components/document-management-dropdown.component.tsx
index 0ace249c..717f521e 100644
--- a/apps/papra-client/src/modules/documents/components/document-management-dropdown.component.tsx
+++ b/apps/papra-client/src/modules/documents/components/document-management-dropdown.component.tsx
@@ -3,7 +3,7 @@ import type { Component } from 'solid-js';
import { queryClient } from '@/modules/shared/query/query-client';
import { Button } from '@/modules/ui/components/button';
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/modules/ui/components/dropdown-menu';
-import { toast } from '@/modules/ui/components/sonner';
+import { createToast } from '@/modules/ui/components/sonner';
import { A } from '@solidjs/router';
import { deleteDocument } from '../documents.services';
@@ -15,7 +15,7 @@ export const DocumentManagementDropdown: Component<{ documentId: string; organiz
});
await queryClient.invalidateQueries({ queryKey: ['organizations', props.organizationId, 'documents'] });
- toast.success('Document deleted');
+ createToast({ type: 'success', message: 'Document deleted' });
};
return (
diff --git a/apps/papra-client/src/modules/organizations/components/create-organization-form.component.tsx b/apps/papra-client/src/modules/organizations/components/create-organization-form.component.tsx
new file mode 100644
index 00000000..b2d52967
--- /dev/null
+++ b/apps/papra-client/src/modules/organizations/components/create-organization-form.component.tsx
@@ -0,0 +1,48 @@
+import type { Component } from 'solid-js';
+import { createForm } from '@/modules/shared/form/form';
+import { Button } from '@/modules/ui/components/button';
+import { TextField, TextFieldLabel, TextFieldRoot } from '@/modules/ui/components/textfield';
+import * as v from 'valibot';
+
+export const CreateOrganizationForm: Component<{
+ onSubmit: (args: { organizationName: string }) => Promise<void>;
+ initialOrganizationName?: string;
+}> = (props) => {
+ const { form, Form, Field } = createForm({
+ onSubmit: ({ organizationName }) => props.onSubmit({ organizationName }),
+ schema: v.object({
+ organizationName: v.pipe(
+ v.string('Organization name must be a string'),
+ v.minLength(3, 'Organization name must be at least 3 characters'),
+ v.maxLength(50, 'Organization name must be at most 50 characters'),
+ ),
+ }),
+ initialValues: {
+ organizationName: props.initialOrganizationName,
+ },
+ });
+
+ return (
+ <div>
+ <Form>
+ <Field name="organizationName">
+ {(field, inputProps) => (
+ <TextFieldRoot class="flex flex-col gap-1 mb-6">
+ <TextFieldLabel for="organizationName">Organization name</TextFieldLabel>
+ <TextField type="text" id="organizationName" placeholder="Eg. Acme Inc." {...inputProps} autoFocus value={field.value} aria-invalid={Boolean(field.error)} />
+ {field.error && <div class="text-red-500 text-sm">{field.error}</div>}
+ </TextFieldRoot>
+ )}
+ </Field>
+
+ <div class="flex justify-end">
+ <Button type="submit" isLoading={form.submitting} class="w-full">
+ Create organization
+ </Button>
+ </div>
+
+ <div class="text-red-500 text-sm mt-4">{form.response.message}</div>
+ </Form>
+ </div>
+ );
+};
diff --git a/apps/papra-client/src/modules/organizations/composables/useCreateOrganization.tsx b/apps/papra-client/src/modules/organizations/composables/useCreateOrganization.tsx
new file mode 100644
index 00000000..b17640ed
--- /dev/null
+++ b/apps/papra-client/src/modules/organizations/composables/useCreateOrganization.tsx
@@ -0,0 +1,22 @@
+import { queryClient } from '@/modules/shared/query/query-client';
+import { createToast } from '@/modules/ui/components/sonner';
+import { useNavigate } from '@solidjs/router';
+import { createOrganization } from '../organizations.services';
+
+export function useCreateOrganization() {
+ const navigate = useNavigate();
+
+ return {
+ createOrganization: async ({ organizationName }: { organizationName: string }) => {
+ const { organization } = await createOrganization({ name: organizationName });
+
+ createToast({ type: 'success', message: 'Organization created' });
+
+ await queryClient.invalidateQueries({
+ queryKey: ['organizations'],
+ });
+
+ navigate(`/organizations/${organization.id}`);
+ },
+ };
+}
diff --git a/apps/papra-client/src/modules/organizations/pages/create-first-organization.page.tsx b/apps/papra-client/src/modules/organizations/pages/create-first-organization.page.tsx
new file mode 100644
index 00000000..ac40875c
--- /dev/null
+++ b/apps/papra-client/src/modules/organizations/pages/create-first-organization.page.tsx
@@ -0,0 +1,35 @@
+import type { Component } from 'solid-js';
+import { useCurrentUser } from '@/modules/users/composables/useCurrentUser';
+import { CreateOrganizationForm } from '../components/create-organization-form.component';
+import { useCreateOrganization } from '../composables/useCreateOrganization';
+
+export const CreateFirstOrganizationPage: Component = () => {
+ const { createOrganization } = useCreateOrganization();
+ const { user } = useCurrentUser();
+
+ const getOrganizationName = () => {
+ const fullName = user.fullName;
+
+ if (fullName && fullName.length > 0) {
+ return `${fullName}'s organization`;
+ }
+
+ return `My organization`;
+ };
+
+ return (
+ <div>
+ <div class="max-w-md mx-auto sm:mt-16 p-6">
+ <h1 class="text-xl font-bold">
+ Create your organization
+ </h1>
+
+ <p class="text-muted-foreground mb-6">
+ Your documents will be grouped by organization. You can create multiple organizations to separate your documents, for your personal use or to collaborate with others.
+ </p>
+
+ <CreateOrganizationForm onSubmit={createOrganization} initialOrganizationName={getOrganizationName()} />
+ </div>
+ </div>
+ );
+};
diff --git a/apps/papra-client/src/modules/organizations/pages/create-organization.page.tsx b/apps/papra-client/src/modules/organizations/pages/create-organization.page.tsx
index f21090dc..9d2cceab 100644
--- a/apps/papra-client/src/modules/organizations/pages/create-organization.page.tsx
+++ b/apps/papra-client/src/modules/organizations/pages/create-organization.page.tsx
@@ -1,33 +1,15 @@
-import { createForm } from '@/modules/shared/form/form';
+import type { Component } from 'solid-js';
import { Button } from '@/modules/ui/components/button';
-import { TextField, TextFieldLabel, TextFieldRoot } from '@/modules/ui/components/textfield';
-import { A, useNavigate } from '@solidjs/router';
-import { type Component, Show } from 'solid-js';
-import { z } from 'zod';
-import { createOrganization } from '../organizations.services';
+import { A } from '@solidjs/router';
+import { CreateOrganizationForm } from '../components/create-organization-form.component';
+import { useCreateOrganization } from '../composables/useCreateOrganization';
export const CreateOrganizationPage: Component = () => {
- const navigate = useNavigate();
-
- const { getInputBindings, submit, onSubmit, getFieldError, getIsSubmitting } = createForm({
- fields: {
- name: {
- schema: z.string()
- .min(3, 'Organization name must be at least 3 characters')
- .max(50, 'Organization name must be at most 50 characters'),
- },
- },
- });
-
- onSubmit(async ({ name }) => {
- const { organization } = await createOrganization({ name });
-
- navigate(`/organizations/${organization.id}`);
- });
+ const { createOrganization } = useCreateOrganization();
return (
<div>
- <div class="max-w-lg mx-auto sm:mt-16 p-6">
+ <div class="max-w-md mx-auto sm:mt-16 p-6">
<Button as={A} href="/" class="mb-4" variant="outline">
<div class="i-tabler-arrow-left mr-2"></div>
@@ -42,17 +24,7 @@ export const CreateOrganizationPage: Component = () => {
Your documents will be grouped by organization. You can create multiple organizations to separate your documents.
</p>
- <form onSubmit={submit}>
- <TextFieldRoot class="flex flex-col gap-1 mb-6">
- <TextFieldLabel for="name">Organization name</TextFieldLabel>
- <TextField type="text" id="name" placeholder="Eg. Acme Inc." {...getInputBindings('name')} />
- <Show when={getFieldError('name')}>{getErrorMessage => <div class="text-red-500 text-sm">{getErrorMessage()}</div>}</Show>
- </TextFieldRoot>
-
- <Button onClick={submit} isLoading={getIsSubmitting()} type="submit">
- Create organization
- </Button>
- </form>
+ <CreateOrganizationForm onSubmit={createOrganization} />
</div>
</div>
);
diff --git a/apps/papra-client/src/modules/payments/pages/checkout-cancel.page.tsx b/apps/papra-client/src/modules/payments/pages/checkout-cancel.page.tsx
index dfd1d0f7..d1b22e79 100644
--- a/apps/papra-client/src/modules/payments/pages/checkout-cancel.page.tsx
+++ b/apps/papra-client/src/modules/payments/pages/checkout-cancel.page.tsx
@@ -1,11 +1,11 @@
import type { Component } from 'solid-js';
import { Navigate } from '@solidjs/router';
import { onMount } from 'solid-js';
-import { toast } from '../../ui/components/sonner';
+import { createToast } from '../../ui/components/sonner';
export const CheckoutCancelPage: Component = () => {
onMount(() => {
- toast.error('Payment canceled');
+ createToast({ type: 'error', message: 'Payment canceled' });
});
return (
diff --git a/apps/papra-client/src/modules/payments/pages/upgrade-plan.page.tsx b/apps/papra-client/src/modules/payments/pages/upgrade-plan.page.tsx
index f82624ac..e172dc62 100644
--- a/apps/papra-client/src/modules/payments/pages/upgrade-plan.page.tsx
+++ b/apps/papra-client/src/modules/payments/pages/upgrade-plan.page.tsx
@@ -3,7 +3,7 @@ import { isHttpErrorWithCode } from '@/modules/shared/http/http-errors';
import { Badge } from '@/modules/ui/components/badge';
import { Button } from '@/modules/ui/components/button';
import { Card } from '@/modules/ui/components/card';
-import { toast } from '@/modules/ui/components/sonner';
+import { createToast } from '@/modules/ui/components/sonner';
import { Tabs, TabsIndicator, TabsList, TabsTrigger } from '@/modules/ui/components/tabs';
import { useCurrentUser } from '@/modules/users/composables/useCurrentUser';
import { createSignal, splitProps } from 'solid-js';
@@ -90,11 +90,11 @@ export const UpgradePlanPage: Component = () => {
window.location.href = checkoutUrl;
} catch (error) {
if (isHttpErrorWithCode({ error, code: 'payment.customer_already_has_subscription' })) {
- toast.error('You already have an active subscription');
+ createToast({ type: 'error', message: 'You already have an active subscription' });
return;
}
- toast.error('An error occurred while processing your request');
+ createToast({ type: 'error', message: 'An error occurred while processing your request' });
}
};
diff --git a/apps/papra-client/src/modules/shared/form/form-legacy.ts b/apps/papra-client/src/modules/shared/form/form-legacy.ts
new file mode 100644
index 00000000..402972a4
--- /dev/null
+++ b/apps/papra-client/src/modules/shared/form/form-legacy.ts
@@ -0,0 +1,146 @@
+import type { z } from 'zod';
+import { flatten, isEmpty, isEqual, map, mapValues } from 'lodash-es';
+import { createSignal } from 'solid-js';
+import { createHook } from '../hooks/hooks';
+
+export type FormRule = {
+ isValid: (value: string) => boolean;
+ message: string;
+};
+
+export type FormField = {
+ initialValue?: string;
+ schema: z.ZodTypeAny;
+};
+
+export function createForm<Keys>({ fields }: { fields: Record<keyof Keys, FormField> }) {
+ const [getForm, setForm] = createSignal<Record<keyof Keys, string>>(mapValues(fields, field => field.initialValue ?? ''));
+ const [getFieldsErrors, setFieldsErrors] = createSignal<Record<keyof Keys, string[]>>(mapValues(fields, () => []));
+ const [getIsSubmitting, setIsSubmitting] = createSignal(false);
+
+ const setField = (key: keyof Keys, value: string) => {
+ setForm(form => ({ ...form, [key]: value }));
+ setFieldsErrors(fieldErrors => ({ ...fieldErrors, [key]: [] }));
+ };
+
+ const getField = (key: keyof Keys) => {
+ return getForm()[key];
+ };
+
+ const validateField = (key: keyof Keys) => {
+ const value = getForm()[key];
+ const schema = fields[key].schema;
+ const result = schema.safeParse(value);
+
+ if (!result.success) {
+ return {
+ isValid: false,
+ errors: result.error.issues.map(issue => issue.message),
+ };
+ }
+
+ return {
+ isValid: true,
+ errors: [],
+ };
+ };
+
+ const triggerFieldValidation = (key: keyof Keys) => {
+ const { isValid, errors } = validateField(key);
+ if (!isValid) {
+ setFieldsErrors(fieldErrors => ({ ...fieldErrors, [key]: errors }));
+ return false;
+ }
+
+ return true;
+ };
+
+ const triggerFieldsValidation = () => {
+ return map(fields, (_, key) => triggerFieldValidation(key as keyof Keys));
+ };
+
+ const getFieldErrors = (key: keyof Keys) => {
+ return getFieldsErrors()[key];
+ };
+
+ const getFieldError = (key: keyof Keys) => {
+ return getFieldErrors(key)[0];
+ };
+
+ const submitHook = createHook<Record<keyof Keys, string>>();
+
+ const submit = async (event?: Event) => {
+ event?.preventDefault();
+ const form = getForm();
+
+ triggerFieldsValidation();
+ const isValid = isEmpty(flatten(Object.values(getFieldsErrors())));
+
+ if (!isValid) {
+ return;
+ }
+
+ setIsSubmitting(true);
+ await submitHook.trigger(form);
+ setIsSubmitting(false);
+ };
+
+ const getInputBindings = (key: keyof Keys) => {
+ return {
+ value: getField(key),
+ onInput: (event: InputEvent) => {
+ const value = (event.target as HTMLInputElement).value;
+ setField(key, value);
+ },
+ onBlur: () => {
+ triggerFieldValidation(key);
+ },
+ };
+ };
+
+ const getFieldStatus = (key: keyof Keys) => {
+ const errors = getFieldErrors(key);
+
+ if (isEmpty(errors)) {
+ return 'valid';
+ }
+
+ return 'invalid';
+ };
+
+ const setFieldError = (key: keyof Keys, errors: string) => {
+ setFieldsErrors(fieldErrors => ({ ...fieldErrors, [key]: [errors] }));
+ };
+
+ const getIsFormDirty = () => {
+ return !isEqual(
+ getForm(),
+ mapValues(fields, field => field.initialValue ?? ''),
+ );
+ };
+
+ const getFormHasErrors = () => {
+ return !isEmpty(flatten(Object.values(getFieldsErrors())));
+ };
+
+ return {
+ getForm,
+ setForm,
+ getField,
+ setField,
+ getFieldsErrors,
+ getFieldError,
+ validateField,
+ triggerFieldValidation,
+ triggerFieldsValidation,
+ getFieldErrors,
+ submit,
+ onSubmit: submitHook.on,
+ getIsSubmitting,
+ getInputBindings,
+ getFieldStatus,
+ setFieldError,
+ getIsFormDirty,
+ getFormHasErrors,
+ };
+}
diff --git a/apps/papra-client/src/modules/shared/form/form.ts b/apps/papra-client/src/modules/shared/form/form.ts
index 402972a4..0dcf2e04 100644
--- a/apps/papra-client/src/modules/shared/form/form.ts
+++ b/apps/papra-client/src/modules/shared/form/form.ts
@@ -1,146 +1,33 @@
-import type { z } from 'zod';
-import { flatten, isEmpty, isEqual, map, mapValues } from 'lodash-es';
-import { createSignal } from 'solid-js';
+import type { FormProps, PartialValues } from '@modular-forms/solid';
+import type * as v from 'valibot';
+import { createForm as createModularForm, valiForm } from '@modular-forms/solid';
import { createHook } from '../hooks/hooks';
-export type FormRule = {
- isValid: (value: string) => boolean;
- message: string;
-};
-
-export type FormField = {
- initialValue?: string;
- schema: z.ZodTypeAny;
-};
-
-export function createForm<Keys>({ fields }: { fields: Record<keyof Keys, FormField> }) {
- const [getForm, setForm] = createSignal<Record<keyof Keys, string>>(mapValues(fields, field => field.initialValue ?? ''));
- const [getFieldsErrors, setFieldsErrors] = createSignal<Record<keyof Keys, string[]>>(mapValues(fields, () => []));
- const [getIsSubmitting, setIsSubmitting] = createSignal(false);
-
- const setField = (key: keyof Keys, value: string) => {
- setForm(form => ({ ...form, [key]: value }));
- setFieldsErrors(fieldErrors => ({ ...fieldErrors, [key]: [] }));
- };
-
- const getField = (key: keyof Keys) => {
- return getForm()[key];
- };
-
- const validateField = (key: keyof Keys) => {
- const value = getForm()[key];
- const schema = fields[key].schema;
- const result = schema.safeParse(value);
-
- if (!result.success) {
- return {
- isValid: false,
- errors: result.error.issues.map(issue => issue.message),
- };
- }
-
- return {
- isValid: true,
- errors: [],
- };
- };
-
- const triggerFieldValidation = (key: keyof Keys) => {
- const { isValid, errors } = validateField(key);
- if (!isValid) {
- setFieldsErrors(fieldErrors => ({ ...fieldErrors, [key]: errors }));
- return false;
- }
-
- return true;
- };
-
- const triggerFieldsValidation = () => {
- return map(fields, (_, key) => triggerFieldValidation(key as keyof Keys));
- };
-
- const getFieldErrors = (key: keyof Keys) => {
- return getFieldsErrors()[key];
- };
-
- const getFieldError = (key: keyof Keys) => {
- return getFieldErrors(key)[0];
- };
-
- const submitHook = createHook<Record<keyof Keys, string>>();
-
- const submit = async (event?: Event) => {
- event?.preventDefault();
- const form = getForm();
-
- triggerFieldsValidation();
- const isValid = isEmpty(flatten(Object.values(getFieldsErrors())));
-
- if (!isValid) {
- return;
- }
-
- setIsSubmitting(true);
- await submitHook.trigger(form);
- setIsSubmitting(false);
- };
-
- const getInputBindings = (key: keyof Keys) => {
- return {
- value: getField(key),
- onInput: (event: InputEvent) => {
- const value = (event.target as HTMLInputElement).value;
- setField(key, value);
- },
- onBlur: () => {
- triggerFieldValidation(key);
- },
- };
- };
-
- const getFieldStatus = (key: keyof Keys) => {
- const errors = getFieldErrors(key);
-
- if (isEmpty(errors)) {
- return 'valid';
- }
-
- return 'invalid';
- };
-
- const setFieldError = (key: keyof Keys, errors: string) => {
- setFieldsErrors(fieldErrors => ({ ...fieldErrors, [key]: [errors] }));
- };
-
- const getIsFormDirty = () => {
- return !isEqual(
- getForm(),
- mapValues(fields, field => field.initialValue ?? ''),
- );
- };
-
- const getFormHasErrors = () => {
- return !isEmpty(flatten(Object.values(getFieldsErrors())));
- };
+export function createForm<Schema extends v.ObjectSchema<any, any>>({
+ schema,
+ initialValues,
+ onSubmit,
+}: {
+ schema: Schema;
+ initialValues?: PartialValues<v.InferInput<Schema>>;
+ onSubmit?: (values: v.InferInput<Schema>) => Promise<void>;
+}) {
+ const submitHook = createHook<v.InferInput<Schema>>();
+
+ if (onSubmit) {
+ submitHook.on(onSubmit);
+ }
+
+ const [form, { Form, Field }] = createModularForm<v.InferInput<Schema>>({
+ validate: valiForm(schema),
+ initialValues,
+ });
return {
- getForm,
- setForm,
- getField,
- setField,
- getFieldsErrors,
- getFieldError,
- validateField,
- triggerFieldValidation,
- triggerFieldsValidation,
- getFieldErrors,
- submit,
+ form,
+ Form: (props: Omit<FormProps<v.InferInput<Schema>, undefined>, 'of'>) => Form({ ...props, onSubmit: submitHook.trigger }),
+ Field,
onSubmit: submitHook.on,
- getIsSubmitting,
- getInputBindings,
- getFieldStatus,
- setFieldError,
- getIsFormDirty,
- getFormHasErrors,
+ submit: submitHook.trigger,
};
}
diff --git a/apps/papra-client/src/modules/ui/components/sonner.tsx b/apps/papra-client/src/modules/ui/components/sonner.tsx
index 8ed57c5d..cd181afe 100644
--- a/apps/papra-client/src/modules/ui/components/sonner.tsx
+++ b/apps/papra-client/src/modules/ui/components/sonner.tsx
@@ -1,4 +1,6 @@
-import { Toaster as Sonner } from 'solid-sonner';
+import type { JSX } from 'solid-js';
+import type { ExternalToast } from 'solid-sonner';
+import { Toaster as Sonner, toast } from 'solid-sonner';
export { toast } from 'solid-sonner';
@@ -14,7 +16,26 @@ export function Toaster(props: Parameters<typeof Sonner>[0]) {
cancelButton: 'group-[.toast]:(bg-muted text-muted-foreground)',
},
}}
+ icons={{
+ success: <div class="i-tabler-circle-check size-5 text-primary"></div>,
+ info: <div class="i-tabler-info-circle size-5 text-primary"></div>,
+ warning: <div class="i-tabler-alert-triangle size-5 text-red"></div>,
+ error: <div class="i-tabler-alert-octagon size-5 text-red"></div>,
+ loading: <div class="i-tabler-loader size-5 text-primary"></div>,
+ }}
+
{...props}
/>
);
}
+
+export function createToast({
+ type = 'message',
+ message,
+ ...rest
+}: {
+ type?: 'success' | 'info' | 'warning' | 'error' | 'message' | 'loading';
+ message: string | JSX.Element;
+} & ExternalToast) {
+ toast[type](message, rest);
+}
diff --git a/apps/papra-client/src/modules/ui/layouts/organization.layout.tsx b/apps/papra-client/src/modules/ui/layouts/organization.layout.tsx
index 71ab8f06..977ae0df 100644
--- a/apps/papra-client/src/modules/ui/layouts/organization.layout.tsx
+++ b/apps/papra-client/src/modules/ui/layouts/organization.layout.tsx
@@ -13,7 +13,7 @@ import { Button } from '@/modules/ui/components/button';
import { useCurrentUser } from '@/modules/users/composables/useCurrentUser';
import { A, useNavigate, useParams } from '@solidjs/router';
import { createQuery } from '@tanstack/solid-query';
-import { type Component, createEffect, type ParentComponent, Show, Suspense } from 'solid-js';
+import { type Component, type ParentComponent, Show, Suspense } from 'solid-js';
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '../components/dropdown-menu';
import {
Select,
@@ -196,20 +196,8 @@ export const OrganizationLayout: ParentComponent = (props) => {
const { user } = useCurrentUser();
const themeStore = useThemeStore();
const params = useParams();
- const navigate = useNavigate();
const { openCommandPalette } = useCommandPalette();
- const query = createQuery(() => ({
- queryKey: ['organizations'],
- queryFn: fetchOrganizations,
- }));
-
- createEffect(() => {
- if (query.data?.organizations && query.data.organizations.length === 0) {
- navigate('/organizations/create');
- }
- });
-
const promptImport = async () => {
const { files } = await promptUploadFiles();
for (const file of files) {
diff --git a/apps/papra-client/src/modules/users/users.types.ts b/apps/papra-client/src/modules/users/users.types.ts
index 8eaec67a..60002025 100644
--- a/apps/papra-client/src/modules/users/users.types.ts
+++ b/apps/papra-client/src/modules/users/users.types.ts
@@ -2,6 +2,7 @@ export type UserMe = {
id: string;
email: string;
planId: string;
+ fullName: string;
roles: string[];
};
diff --git a/apps/papra-client/src/routes.tsx b/apps/papra-client/src/routes.tsx
index d4aff95b..153e4dab 100644
--- a/apps/papra-client/src/routes.tsx
+++ b/apps/papra-client/src/routes.tsx
@@ -1,4 +1,6 @@
import { A, Navigate, type RouteDefinition, useParams } from '@solidjs/router';
+import { createQuery } from '@tanstack/solid-query';
+import { Match, Suspense, Switch } from 'solid-js';
import { createProtectedPage } from './modules/auth/middleware/protected-page.middleware';
import { ConfirmPage } from './modules/auth/pages/confirm.page';
import { GenericAuthPage } from './modules/auth/pages/generic-auth.page';
@@ -6,6 +8,8 @@ import { MagicLinkSentPage } from './modules/auth/pages/magic-link-sent.page';
import { PendingMagicLinkPage } from './modules/auth/pages/verify-magic-link.page';
import { DocumentPage } from './modules/documents/pages/document.page';
import { DocumentsPage } from './modules/documents/pages/documents.page';
+import { fetchOrganizations } from './modules/organizations/organizations.services';
+import { CreateFirstOrganizationPage } from './modules/organizations/pages/create-first-organization.page';
import { CreateOrganizationPage } from './modules/organizations/pages/create-organization.page';
import { OrganizationsPage } from './modules/organizations/pages/organizations.page';
import { CheckoutCancelPage } from './modules/payments/pages/checkout-cancel.page';
@@ -24,11 +28,28 @@ export const routes: RouteDefinition[] = [
component: () => {
const { getLatestOrganizationId } = useCurrentUser();
+ const query = createQuery(() => ({
+ queryKey: ['organizations'],
+ queryFn: fetchOrganizations,
+ }));
+
return (
<>
- {getLatestOrganizationId()
- ? <Navigate href={`/organizations/${getLatestOrganizationId()}`} />
- : <Navigate href="/organizations" />}
+ <Suspense>
+ <Switch>
+ <Match when={getLatestOrganizationId() && query.data && query.data.organizations.some(org => org.id === getLatestOrganizationId())}>
+ <Navigate href={`/organizations/${getLatestOrganizationId()}`} />
+ </Match>
+
+ <Match when={query.data && query.data.organizations.length > 0}>
+ <Navigate href="/organizations" />
+ </Match>
+
+ <Match when={query.data && query.data.organizations.length === 0}>
+ <Navigate href="/organizations/first" />
+ </Match>
+ </Switch>
+ </Suspense>
</>
);
@@ -64,20 +85,16 @@ export const routes: RouteDefinition[] = [
path: '/documents/:documentId',
component: DocumentPage,
},
- // {
- // path: '/documents',
- // component: () => {
- // const params = useParams();
-
- // return <Navigate href={`/organizations/${params.organizationId}`} />;
- // },
- // },
],
},
{
path: '/create',
component: CreateOrganizationPage,
},
+ {
+ path: '/first',
+ component: CreateFirstOrganizationPage,
+ },
// {
// path: '/settings',
// component: SettingsLayout,
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 7c93b255..5f6c20ec 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -34,6 +34,9 @@ importers:
'@kobalte/core':
specifier: ^0.13.4
version: 0.13.7([email protected])
+ '@modular-forms/solid':
+ specifier: ^0.25.0
'@pdfslick/solid':
specifier: ^2.0.0
@@ -94,6 +97,9 @@ importers:
uqr:
specifier: ^0.1.2
version: 0.1.2
+ valibot:
+ specifier: 1.0.0-beta.10
+ version: 1.0.0-beta.10([email protected])
zod:
specifier: ^3.23.8
version: 3.24.1
@@ -1439,6 +1445,11 @@ packages:
cpu: [x64]
os: [win32]
+ '@modular-forms/[email protected]':
+ resolution: {integrity: sha512-fmahVRnYSjQGxWwkuTqOLb4OnleIeu2ROU9iE3Ln7Z4KA829iLgTLQBHE/SIB4ZfkDuS8XLbN8Dn+7m+D6XimA==}
+ peerDependencies:
+ solid-js: ^1.3.1
+
'@napi-rs/[email protected]':
resolution: {integrity: sha512-ZYwqFYEKcT5Zr8lbiaJNJj/poLaeK2TncolY914r+gD2TJNeP7ZqvE7A2SX/1C9MB4E3DQEwm3YhL3WEf0x3MQ==}
engines: {node: '>= 10'}
@@ -4057,6 +4068,14 @@ packages:
resolution: {integrity: sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==}
hasBin: true
+ resolution: {integrity: sha512-nmo3nxvXRrxwDYZznK3aTgYv7ZA/SUZJ/s+pLY4Tqsex/fgwZ9XrrQ14jjozjUaeduQ9PhXHE2Xx1uMb0HePYw==}
+ peerDependencies:
+ typescript: '>=5'
+ peerDependenciesMeta:
+ typescript:
+ optional: true
+
resolution: {integrity: sha512-hGdgQozCsQJMyfK5urgFcWEqsSSrK63Awe0t/IMR0bZ0QMtnuaiHzThW81guu3qx9abLi99NEuiaN6P9gVYsNg==}
@@ -5632,6 +5651,13 @@ snapshots:
'@libsql/[email protected]':
optional: true
+ dependencies:
+ solid-js: 1.9.3
+ valibot: 1.0.0-beta.10([email protected])
+ transitivePeerDependencies:
+ - typescript
+
'@napi-rs/[email protected]':
optional: true
@@ -8776,6 +8802,10 @@ snapshots:
+ optionalDependencies:
+ typescript: 5.7.2
+