@solibo/solibo-react 1.57.8 → 1.57.9-e275c87-1795638776357-SNAPSHOT
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/commands/board/useSetBoardMemberTerm.d.ts +5 -0
- package/dist/api/commands/board/useSetBoardMemberTerm.js +9 -0
- package/dist/api/commands/conversation/useConversationFolders.d.ts +1 -4
- package/dist/api/commands/conversation/useConversationHelpers.d.ts +16 -0
- package/dist/api/commands/conversation/useConversationHelpers.js +25 -0
- package/dist/api/commands/document/useIntegratedDocumentMutations.d.ts +18 -18
- package/dist/api/commands/document/useIntegratedRetry.d.ts +34 -0
- package/dist/api/commands/document/useIntegratedRetry.js +56 -0
- package/dist/api/commands/document/useOwnedDocumentMutations.d.ts +29 -0
- package/dist/api/commands/document/useOwnedDocumentMutations.js +128 -0
- package/dist/api/commands/economy/useCreateInvoiceComment.d.ts +5 -0
- package/dist/api/commands/economy/useCreateInvoiceComment.js +9 -0
- package/dist/api/commands/expense/useDeleteExpense.d.ts +1 -0
- package/dist/api/commands/homepage/useDeleteHomepageImage.d.ts +5 -0
- package/dist/api/commands/homepage/useDeleteHomepageImage.js +10 -0
- package/dist/api/commands/insurance/useDeleteInsurance.d.ts +1 -0
- package/dist/api/commands/invoicing/useDeleteAdHocLineGroup.d.ts +1 -0
- package/dist/api/commands/issue/useDeleteIssue.d.ts +1 -0
- package/dist/api/commands/loan/useUpdateLoan.d.ts +1 -0
- package/dist/api/commands/meeting/useDeleteMeeting.d.ts +1 -0
- package/dist/api/commands/resident/useUpdateResidentContact.d.ts +6 -0
- package/dist/api/commands/resident/useUpdateResidentContact.js +14 -0
- package/dist/api/commands/routines/useDeleteRoutine.d.ts +1 -0
- package/dist/api/commands/settlement/useDeleteSettlement.d.ts +1 -0
- package/dist/api/commands/settlement/useDeleteSettlementCustomCost.d.ts +1 -0
- package/dist/api/queries/company/useCompanyNames.d.ts +27 -0
- package/dist/api/queries/company/useCompanyNames.js +50 -0
- package/dist/api/queries/countries/useCountryLookup.d.ts +25 -0
- package/dist/api/queries/countries/useCountryLookup.js +36 -0
- package/dist/api/queries/document/useDocumentURL.d.ts +46 -0
- package/dist/api/queries/document/useDocumentURL.js +58 -0
- package/dist/api/queries/invoicing/usePlannedInvoicePreviews.d.ts +3 -0
- package/dist/api/queries/invoicing/usePlannedInvoicePreviews.js +7 -0
- package/dist/api/queries/user/useCompanyActions.d.ts +27 -0
- package/dist/api/queries/user/useCompanyActions.js +40 -0
- package/dist/api/queries/utilityUsage/useUtilityUsage.d.ts +4 -0
- package/dist/api/queries/utilityUsage/useUtilityUsage.js +11 -0
- package/dist/events/index.d.ts +2 -0
- package/dist/events/index.js +2 -0
- package/dist/events/useDomainEvents.d.ts +29 -0
- package/dist/events/useDomainEvents.js +52 -0
- package/dist/events/useLiveHomepage.d.ts +10 -0
- package/dist/events/useLiveHomepage.js +43 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +15 -0
- package/dist/sharedText/index.d.ts +1 -0
- package/dist/sharedText/index.js +1 -0
- package/dist/sharedText/useSharedText.d.ts +48 -0
- package/dist/sharedText/useSharedText.js +55 -0
- package/dist/utils/pages.d.ts +42 -0
- package/dist/utils/pages.js +50 -0
- package/dist/utils/useByteArrayUrl.d.ts +7 -0
- package/dist/utils/useByteArrayUrl.js +18 -0
- package/package.json +40 -5
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useQuery } from '@tanstack/react-query';
|
|
2
|
+
import { allCountriesQueryOptions, countryById, preferredLanguageCountryId, userQueryOptions, } from '@solibo/solibo-query';
|
|
3
|
+
import { useSdk } from '../../../sdkProvider.js';
|
|
4
|
+
/** Every country by id (`String(id)`), read once and kept for a day. */
|
|
5
|
+
export const useCountryLookup = (options = {}) => {
|
|
6
|
+
const sdk = useSdk();
|
|
7
|
+
return useQuery({
|
|
8
|
+
...allCountriesQueryOptions(sdk),
|
|
9
|
+
enabled: options.enabled ?? true,
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
/** A country by id, with its ISO code (`iso`), from the cached lookup. */
|
|
13
|
+
export const useCountry = (countryId) => {
|
|
14
|
+
const lookup = useCountryLookup({ enabled: countryId != null });
|
|
15
|
+
return {
|
|
16
|
+
country: countryById(lookup.data, countryId),
|
|
17
|
+
isPending: countryId != null && lookup.isPending,
|
|
18
|
+
isError: lookup.isError,
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* The country of the language the signed-in user prefers (`preferredLanguage` is a country id).
|
|
23
|
+
* Map its ISO code to the app's own languages; the SDK does not hard-code country ids.
|
|
24
|
+
*/
|
|
25
|
+
export const usePreferredLanguageCountry = () => {
|
|
26
|
+
const sdk = useSdk();
|
|
27
|
+
const user = useQuery(userQueryOptions(sdk));
|
|
28
|
+
const countryId = preferredLanguageCountryId(user.data);
|
|
29
|
+
const { country, isPending, isError } = useCountry(countryId);
|
|
30
|
+
return {
|
|
31
|
+
country,
|
|
32
|
+
iso: country?.iso ? country.iso.toUpperCase() : undefined,
|
|
33
|
+
isPending: user.isPending || isPending,
|
|
34
|
+
isError: user.isError || isError,
|
|
35
|
+
};
|
|
36
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Id } from '@solibo/solibo-sdk';
|
|
2
|
+
import { type ImageTransformOptions } from '@solibo/solibo-query';
|
|
3
|
+
/**
|
|
4
|
+
* Where a document is read from, which decides the endpoint that signs its URL:
|
|
5
|
+
* - `company`: a signed-in reader of the company's documents (the default);
|
|
6
|
+
* - `public`: a document the company publishes, read without signing in;
|
|
7
|
+
* - `homepagePost`: a file of a homepage post or practical information, on the open homepage;
|
|
8
|
+
* - `publicConversation`: a file of a public conversation, by company slug.
|
|
9
|
+
*/
|
|
10
|
+
export type DocumentURLSource = {
|
|
11
|
+
kind: 'company';
|
|
12
|
+
} | {
|
|
13
|
+
kind: 'public';
|
|
14
|
+
} | {
|
|
15
|
+
kind: 'homepagePost';
|
|
16
|
+
postId: Id;
|
|
17
|
+
} | {
|
|
18
|
+
kind: 'publicConversation';
|
|
19
|
+
companySlug: string;
|
|
20
|
+
conversationId: Id;
|
|
21
|
+
};
|
|
22
|
+
export type UseDocumentURLParams = ImageTransformOptions & {
|
|
23
|
+
companyId?: Id | null | undefined;
|
|
24
|
+
documentId?: Id | null | undefined;
|
|
25
|
+
/** Defaults to `{ kind: 'company' }`. */
|
|
26
|
+
source?: DocumentURLSource;
|
|
27
|
+
/** False holds the lookup back, such as until the document scrolls into view. */
|
|
28
|
+
enabled?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Whether the document is shown now. A URL that went stale while it was hidden is signed
|
|
31
|
+
* again when it is shown, so an image never loads from an expired URL. Defaults to true.
|
|
32
|
+
*/
|
|
33
|
+
visible?: boolean;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* How long a signed URL is used before it is signed again. The backend's signed URLs live an hour;
|
|
37
|
+
* this leaves a quarter of that for a page that stays open.
|
|
38
|
+
*/
|
|
39
|
+
export declare const DOCUMENT_URL_STALE_TIME: number;
|
|
40
|
+
/**
|
|
41
|
+
* The signed URL of a document to show (`data.url`), from the endpoint that fits `source`. Lookups
|
|
42
|
+
* made together share one request where the endpoint allows it. The URL is used for 45 minutes,
|
|
43
|
+
* below its hour-long lifetime, and signed again when a stale one is shown again (`visible`).
|
|
44
|
+
* A definitive refusal (403, 404) is not retried.
|
|
45
|
+
*/
|
|
46
|
+
export declare const useDocumentURL: (params: UseDocumentURLParams) => import("@tanstack/react-query").UseQueryResult<import("@solibo/solibo-sdk").UrlWrapper, unknown>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { useQuery } from '@tanstack/react-query';
|
|
3
|
+
import { getDocumentURLQueryOptions, isDefinitiveRejection, minutes, openHomepageDocumentQueryOptions, publicConversationDocumentURLQueryOptions, publicGetDocumentURLQueryOptions, } from '@solibo/solibo-query';
|
|
4
|
+
import { useSdk } from '../../../sdkProvider.js';
|
|
5
|
+
/**
|
|
6
|
+
* How long a signed URL is used before it is signed again. The backend's signed URLs live an hour;
|
|
7
|
+
* this leaves a quarter of that for a page that stays open.
|
|
8
|
+
*/
|
|
9
|
+
export const DOCUMENT_URL_STALE_TIME = minutes(45);
|
|
10
|
+
const retryDocumentURL = (failureCount, error) => !isDefinitiveRejection(error) && failureCount < 2;
|
|
11
|
+
function documentURLQueryOptions(sdk, { source = { kind: 'company' }, enabled: _enabled, visible: _visible, ...params }) {
|
|
12
|
+
switch (source.kind) {
|
|
13
|
+
case 'public':
|
|
14
|
+
return publicGetDocumentURLQueryOptions(sdk, params);
|
|
15
|
+
case 'homepagePost':
|
|
16
|
+
return openHomepageDocumentQueryOptions(sdk, {
|
|
17
|
+
...params,
|
|
18
|
+
postId: source.postId,
|
|
19
|
+
redirect: false,
|
|
20
|
+
});
|
|
21
|
+
case 'publicConversation':
|
|
22
|
+
return publicConversationDocumentURLQueryOptions(sdk, {
|
|
23
|
+
...params,
|
|
24
|
+
companySlug: source.companySlug,
|
|
25
|
+
conversationId: source.conversationId,
|
|
26
|
+
});
|
|
27
|
+
default:
|
|
28
|
+
return getDocumentURLQueryOptions(sdk, params);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The signed URL of a document to show (`data.url`), from the endpoint that fits `source`. Lookups
|
|
33
|
+
* made together share one request where the endpoint allows it. The URL is used for 45 minutes,
|
|
34
|
+
* below its hour-long lifetime, and signed again when a stale one is shown again (`visible`).
|
|
35
|
+
* A definitive refusal (403, 404) is not retried.
|
|
36
|
+
*/
|
|
37
|
+
export const useDocumentURL = (params) => {
|
|
38
|
+
const sdk = useSdk();
|
|
39
|
+
const options = documentURLQueryOptions(sdk, params);
|
|
40
|
+
const query = useQuery({
|
|
41
|
+
...options,
|
|
42
|
+
enabled: (params.enabled ?? true) && options.enabled,
|
|
43
|
+
staleTime: DOCUMENT_URL_STALE_TIME,
|
|
44
|
+
retry: retryDocumentURL,
|
|
45
|
+
});
|
|
46
|
+
const visible = params.visible ?? true;
|
|
47
|
+
const { isStale, isFetching, isError, refetch } = query;
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (visible &&
|
|
50
|
+
isStale &&
|
|
51
|
+
!isFetching &&
|
|
52
|
+
!isError &&
|
|
53
|
+
query.data !== undefined) {
|
|
54
|
+
void refetch({ cancelRefetch: false });
|
|
55
|
+
}
|
|
56
|
+
}, [visible, isStale, isFetching, isError, refetch, query.data]);
|
|
57
|
+
return query;
|
|
58
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { plannedInvoicePreviewsQueryOptions } from '@solibo/solibo-query';
|
|
2
|
+
import type { RestParams } from '../../../utils/restParams.js';
|
|
3
|
+
export declare const usePlannedInvoicePreviews: (...args: RestParams<typeof plannedInvoicePreviewsQueryOptions>) => import("@tanstack/react-query").UseInfiniteQueryResult<import("@tanstack/query-core").InfiniteData<import("@solibo/solibo-sdk").PagedListPlannedInvoicePreview, unknown>, Error>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { useInfiniteQuery } from '@tanstack/react-query';
|
|
2
|
+
import { useSdk } from '../../../sdkProvider.js';
|
|
3
|
+
import { plannedInvoicePreviewsQueryOptions } from '@solibo/solibo-query';
|
|
4
|
+
export const usePlannedInvoicePreviews = (...args) => {
|
|
5
|
+
const sdk = useSdk();
|
|
6
|
+
return useInfiniteQuery(plannedInvoicePreviewsQueryOptions(sdk, ...args));
|
|
7
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Id } from '@solibo/solibo-sdk';
|
|
2
|
+
export interface CompanyActions {
|
|
3
|
+
/** The action patterns the signed-in user holds in the company, every page of them. */
|
|
4
|
+
actions: string[];
|
|
5
|
+
/** Whether the actions cover `action` (backend `*` wildcards); false until every page loaded. */
|
|
6
|
+
has: (action: string) => boolean;
|
|
7
|
+
/** True while the actions load; false without a company. */
|
|
8
|
+
isPending: boolean;
|
|
9
|
+
isComplete: boolean;
|
|
10
|
+
isError: boolean;
|
|
11
|
+
error: unknown;
|
|
12
|
+
refetch: () => Promise<unknown>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The actions the signed-in user may perform in a company, all pages loaded once and kept for five
|
|
16
|
+
* minutes, shared by every caller for the same company.
|
|
17
|
+
*/
|
|
18
|
+
export declare const useCompanyActions: (companyId: Id | null | undefined) => CompanyActions;
|
|
19
|
+
export interface HasAction {
|
|
20
|
+
/** Whether the user may perform the action; false while loading, on error and without a company. */
|
|
21
|
+
allowed: boolean;
|
|
22
|
+
isPending: boolean;
|
|
23
|
+
isError: boolean;
|
|
24
|
+
refetch: () => Promise<unknown>;
|
|
25
|
+
}
|
|
26
|
+
/** Whether the signed-in user may perform `action` (such as `PutCompanyDetailed`) in a company. */
|
|
27
|
+
export declare const useHasAction: (companyId: Id | null | undefined, action: string) => HasAction;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useCallback, useMemo } from 'react';
|
|
2
|
+
import { useInfiniteQuery } from '@tanstack/react-query';
|
|
3
|
+
import { matchesAction, minutes, userActionsQueryOptions, } from '@solibo/solibo-query';
|
|
4
|
+
import { useSdk } from '../../../sdkProvider.js';
|
|
5
|
+
import { MAX_PAGE_SIZE, useAllPages } from '../../../utils/pages.js';
|
|
6
|
+
const hasCompanyId = (companyId) => companyId != null && companyId !== '';
|
|
7
|
+
/**
|
|
8
|
+
* The actions the signed-in user may perform in a company, all pages loaded once and kept for five
|
|
9
|
+
* minutes, shared by every caller for the same company.
|
|
10
|
+
*/
|
|
11
|
+
export const useCompanyActions = (companyId) => {
|
|
12
|
+
const sdk = useSdk();
|
|
13
|
+
const enabled = hasCompanyId(companyId);
|
|
14
|
+
const query = useInfiniteQuery({
|
|
15
|
+
...userActionsQueryOptions(sdk, {
|
|
16
|
+
companyId: enabled ? companyId : undefined,
|
|
17
|
+
count: MAX_PAGE_SIZE,
|
|
18
|
+
}),
|
|
19
|
+
staleTime: minutes(5),
|
|
20
|
+
});
|
|
21
|
+
const all = useAllPages(query, enabled);
|
|
22
|
+
const { items, isComplete } = all;
|
|
23
|
+
const actions = useMemo(() => items.map(String), [items]);
|
|
24
|
+
const has = useCallback((action) => isComplete && matchesAction(actions, action), [actions, isComplete]);
|
|
25
|
+
const { refetch } = query;
|
|
26
|
+
return {
|
|
27
|
+
actions,
|
|
28
|
+
has,
|
|
29
|
+
isPending: enabled && all.isPending,
|
|
30
|
+
isComplete: enabled && isComplete,
|
|
31
|
+
isError: enabled && all.isError,
|
|
32
|
+
error: all.error,
|
|
33
|
+
refetch,
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
/** Whether the signed-in user may perform `action` (such as `PutCompanyDetailed`) in a company. */
|
|
37
|
+
export const useHasAction = (companyId, action) => {
|
|
38
|
+
const { has, isPending, isError, refetch } = useCompanyActions(companyId);
|
|
39
|
+
return { allowed: has(action), isPending, isError, refetch };
|
|
40
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { companyUtilityUsageQueryOptions, sectionUtilityUsageQueryOptions } from '@solibo/solibo-query';
|
|
2
|
+
import type { RestParams } from '../../../utils/restParams.js';
|
|
3
|
+
export declare const useCompanyUtilityUsage: (...args: RestParams<typeof companyUtilityUsageQueryOptions>) => import("@tanstack/react-query").UseQueryResult<import("@solibo/solibo-sdk").CompanyUtilityUsage, Error>;
|
|
4
|
+
export declare const useSectionUtilityUsage: (...args: RestParams<typeof sectionUtilityUsageQueryOptions>) => import("@tanstack/react-query").UseQueryResult<import("@solibo/solibo-sdk").SectionUtilityUsage, Error>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useQuery } from '@tanstack/react-query';
|
|
2
|
+
import { useSdk } from '../../../sdkProvider.js';
|
|
3
|
+
import { companyUtilityUsageQueryOptions, sectionUtilityUsageQueryOptions, } from '@solibo/solibo-query';
|
|
4
|
+
export const useCompanyUtilityUsage = (...args) => {
|
|
5
|
+
const sdk = useSdk();
|
|
6
|
+
return useQuery(companyUtilityUsageQueryOptions(sdk, ...args));
|
|
7
|
+
};
|
|
8
|
+
export const useSectionUtilityUsage = (...args) => {
|
|
9
|
+
const sdk = useSdk();
|
|
10
|
+
return useQuery(sectionUtilityUsageQueryOptions(sdk, ...args));
|
|
11
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import '@solibo/solibo-sdk/events';
|
|
2
|
+
import { DomainEventPayload } from '@solibo/solibo-sdk/core';
|
|
3
|
+
/** What a domain event subscription narrows to. A part left out does not narrow. */
|
|
4
|
+
export type DomainEventFilter = {
|
|
5
|
+
/** Wire names or their prefixes, such as `homepage.post.updated` or `homepage.`. */
|
|
6
|
+
eventTypes?: readonly string[];
|
|
7
|
+
companyIds?: readonly (bigint | number)[];
|
|
8
|
+
/** An event about the entity, or one that names it among its related ids. */
|
|
9
|
+
entities?: readonly {
|
|
10
|
+
type: string;
|
|
11
|
+
id: string;
|
|
12
|
+
}[];
|
|
13
|
+
};
|
|
14
|
+
export type UseDomainEventsOptions = DomainEventFilter & {
|
|
15
|
+
/** False keeps the subscription off, for example until the company is known. */
|
|
16
|
+
enabled?: boolean;
|
|
17
|
+
onEvent: (event: DomainEventPayload) => void;
|
|
18
|
+
/**
|
|
19
|
+
* The connection came back after it had been open for this subscription. A person's
|
|
20
|
+
* subscriptions are live only, so events made while it was down are not sent later: read the
|
|
21
|
+
* current state again here. The first connection does not call it.
|
|
22
|
+
*/
|
|
23
|
+
onReconnect?: () => void;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Follows domain events while the component is mounted, as one subscription of the shared event
|
|
27
|
+
* bus connection. The caller sees only the events it may read over REST that match the filter.
|
|
28
|
+
*/
|
|
29
|
+
export declare const useDomainEvents: ({ companyIds, enabled, entities, eventTypes, onEvent, onReconnect, }: UseDomainEventsOptions) => void;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import '@solibo/solibo-sdk/events';
|
|
2
|
+
import { DomainEventPayload, EventEntityRef } from '@solibo/solibo-sdk/core';
|
|
3
|
+
import { useEffect, useRef } from 'react';
|
|
4
|
+
import { useSdk } from '../sdkProvider.js';
|
|
5
|
+
let subscriptions = 0;
|
|
6
|
+
const filterKey = ({ companyIds, entities, eventTypes }) => JSON.stringify([
|
|
7
|
+
eventTypes ?? null,
|
|
8
|
+
companyIds?.map((id) => id.toString()) ?? null,
|
|
9
|
+
entities ?? null,
|
|
10
|
+
]);
|
|
11
|
+
/**
|
|
12
|
+
* Follows domain events while the component is mounted, as one subscription of the shared event
|
|
13
|
+
* bus connection. The caller sees only the events it may read over REST that match the filter.
|
|
14
|
+
*/
|
|
15
|
+
export const useDomainEvents = ({ companyIds, enabled = true, entities, eventTypes, onEvent, onReconnect, }) => {
|
|
16
|
+
const sdk = useSdk();
|
|
17
|
+
const onEventRef = useRef(onEvent);
|
|
18
|
+
const onReconnectRef = useRef(onReconnect);
|
|
19
|
+
const key = filterKey({ companyIds, entities, eventTypes });
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
onEventRef.current = onEvent;
|
|
22
|
+
onReconnectRef.current = onReconnect;
|
|
23
|
+
});
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (!enabled)
|
|
26
|
+
return;
|
|
27
|
+
const eventBus = sdk.eventBus;
|
|
28
|
+
subscriptions += 1;
|
|
29
|
+
const subscriptionKey = `live-${subscriptions}`;
|
|
30
|
+
const [types, companies, refs] = JSON.parse(key);
|
|
31
|
+
const stopEvents = eventBus.onEvent(({ payload }) => {
|
|
32
|
+
if (payload instanceof DomainEventPayload &&
|
|
33
|
+
payload.subscriptionKey === subscriptionKey) {
|
|
34
|
+
onEventRef.current(payload);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
let wasConnected = eventBus.connected;
|
|
38
|
+
const stopConnection = eventBus.onConnectionChange((connected) => {
|
|
39
|
+
if (!connected)
|
|
40
|
+
return;
|
|
41
|
+
if (wasConnected)
|
|
42
|
+
onReconnectRef.current?.();
|
|
43
|
+
wasConnected = true;
|
|
44
|
+
});
|
|
45
|
+
eventBus.subscribe(subscriptionKey, types, null, null, null, companies?.map((id) => BigInt(id)) ?? null, refs?.map((ref) => new EventEntityRef(ref.id, ref.type)) ?? null);
|
|
46
|
+
return () => {
|
|
47
|
+
stopEvents();
|
|
48
|
+
stopConnection();
|
|
49
|
+
eventBus.unsubscribe(subscriptionKey);
|
|
50
|
+
};
|
|
51
|
+
}, [enabled, key, sdk]);
|
|
52
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type UseLiveHomepageOptions = {
|
|
2
|
+
enabled?: boolean;
|
|
3
|
+
};
|
|
4
|
+
/**
|
|
5
|
+
* Keeps a company's homepage on screen current: when a post or practical information changes,
|
|
6
|
+
* also while someone types in a co-edited one, its feed, posts, practical information and
|
|
7
|
+
* attachments are read again. A burst of changes is read once, a second after the last one, and
|
|
8
|
+
* at least every five seconds while it lasts.
|
|
9
|
+
*/
|
|
10
|
+
export declare const useLiveHomepage: (companyId: bigint | number | null | undefined, { enabled }?: UseLiveHomepageOptions) => void;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { homepageKeys } from '@solibo/solibo-query';
|
|
2
|
+
import { useQueryClient } from '@tanstack/react-query';
|
|
3
|
+
import { useCallback, useEffect, useRef } from 'react';
|
|
4
|
+
import { useDomainEvents } from './useDomainEvents.js';
|
|
5
|
+
const REFRESH_DELAY_MS = 1000;
|
|
6
|
+
const REFRESH_MAX_WAIT_MS = 5000;
|
|
7
|
+
/**
|
|
8
|
+
* Keeps a company's homepage on screen current: when a post or practical information changes,
|
|
9
|
+
* also while someone types in a co-edited one, its feed, posts, practical information and
|
|
10
|
+
* attachments are read again. A burst of changes is read once, a second after the last one, and
|
|
11
|
+
* at least every five seconds while it lasts.
|
|
12
|
+
*/
|
|
13
|
+
export const useLiveHomepage = (companyId, { enabled = true } = {}) => {
|
|
14
|
+
const queryClient = useQueryClient();
|
|
15
|
+
const timer = useRef(undefined);
|
|
16
|
+
const firstPending = useRef(undefined);
|
|
17
|
+
useEffect(() => () => clearTimeout(timer.current), []);
|
|
18
|
+
const refresh = useCallback(() => {
|
|
19
|
+
if (companyId == null)
|
|
20
|
+
return;
|
|
21
|
+
const now = Date.now();
|
|
22
|
+
firstPending.current ?? (firstPending.current = now);
|
|
23
|
+
const delay = Math.min(REFRESH_DELAY_MS, firstPending.current + REFRESH_MAX_WAIT_MS - now);
|
|
24
|
+
clearTimeout(timer.current);
|
|
25
|
+
timer.current = setTimeout(() => {
|
|
26
|
+
firstPending.current = undefined;
|
|
27
|
+
[
|
|
28
|
+
homepageKeys.feed(companyId),
|
|
29
|
+
homepageKeys.feedPost(companyId),
|
|
30
|
+
homepageKeys.practicalInformation(companyId),
|
|
31
|
+
homepageKeys.detail(companyId),
|
|
32
|
+
homepageKeys.postDocuments(companyId),
|
|
33
|
+
].forEach((key) => void queryClient.invalidateQueries({ queryKey: [key] }));
|
|
34
|
+
}, Math.max(0, delay));
|
|
35
|
+
}, [companyId, queryClient]);
|
|
36
|
+
useDomainEvents({
|
|
37
|
+
companyIds: companyId == null ? undefined : [companyId],
|
|
38
|
+
enabled: enabled && companyId != null,
|
|
39
|
+
eventTypes: ['homepage.'],
|
|
40
|
+
onEvent: refresh,
|
|
41
|
+
onReconnect: refresh,
|
|
42
|
+
});
|
|
43
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -4,9 +4,21 @@ export { SoliboProvider, SdkProvider, useSoliboApi, useSdk, SoliboContext, creat
|
|
|
4
4
|
export type { CreateSdkArgs } from './sdkProvider.js';
|
|
5
5
|
export { useMutation } from './utils/useMutation.js';
|
|
6
6
|
export type { MutationResultWithValidation } from './utils/useMutation.js';
|
|
7
|
+
export { DEFAULT_PAGE_SIZE, MAX_PAGE_SIZE, useAllPages, usePagedItems, } from './utils/pages.js';
|
|
8
|
+
export type { AllPagesQuery, AllPagesResult, PagedQueryData, } from './utils/pages.js';
|
|
9
|
+
export { useByteArrayUrl } from './utils/useByteArrayUrl.js';
|
|
10
|
+
export * from './api/queries/user/useCompanyActions.js';
|
|
11
|
+
export * from './api/queries/document/useDocumentURL.js';
|
|
12
|
+
export * from './api/queries/company/useCompanyNames.js';
|
|
13
|
+
export * from './api/queries/countries/useCountryLookup.js';
|
|
14
|
+
export * from './api/commands/homepage/useDeleteHomepageImage.js';
|
|
15
|
+
export * from './api/commands/conversation/useConversationHelpers.js';
|
|
16
|
+
export * from './api/commands/resident/useUpdateResidentContact.js';
|
|
17
|
+
export * from './api/commands/document/useOwnedDocumentMutations.js';
|
|
7
18
|
export { useOpenApiOperationMutation, useOpenApiOperationQuery, } from './api/useOpenApiOperation.js';
|
|
8
19
|
export * from './api/commands/board/useCreateBoardMember.js';
|
|
9
20
|
export * from './api/commands/board/useDeleteBoardMember.js';
|
|
21
|
+
export * from './api/commands/board/useSetBoardMemberTerm.js';
|
|
10
22
|
export * from './api/commands/board/useInviteBoardMemberToSoliboHome.js';
|
|
11
23
|
export * from './api/commands/communication/useBuySMSBundle.js';
|
|
12
24
|
export * from './api/commands/communication/useCreateNewsletter.js';
|
|
@@ -98,12 +110,14 @@ export * from './api/commands/document/useUpdateDocument.js';
|
|
|
98
110
|
export * from './api/commands/document/useTrashMultipleDocuments.js';
|
|
99
111
|
export * from './api/commands/document/useUploadDocument.js';
|
|
100
112
|
export * from './api/commands/document/useIntegratedDocumentMutations.js';
|
|
113
|
+
export * from './api/commands/document/useIntegratedRetry.js';
|
|
101
114
|
export * from './api/commands/economy/useApproveInvoice.js';
|
|
102
115
|
export * from './api/commands/economy/useAttachDocumentToEconomicReport.js';
|
|
103
116
|
export * from './api/commands/economy/useCreateInvoiceNotice.js';
|
|
104
117
|
export * from './api/commands/economy/useDeleteEconomicReport.js';
|
|
105
118
|
export * from './api/commands/economy/useOrderEconomicReport.js';
|
|
106
119
|
export * from './api/commands/economy/useRejectInvoice.js';
|
|
120
|
+
export * from './api/commands/economy/useCreateInvoiceComment.js';
|
|
107
121
|
export * from './api/commands/economy/useUpdateInvoiceNotification.js';
|
|
108
122
|
export * from './api/commands/economy/useUpdateRealtimeInvoiceNotification.js';
|
|
109
123
|
export * from './api/commands/expense/useApproveExpense.js';
|
|
@@ -449,6 +463,8 @@ export * from './api/queries/invoicing/useSectionInvoices.js';
|
|
|
449
463
|
export * from './api/queries/invoicing/useSectionInvoicesQueries.js';
|
|
450
464
|
export * from './api/queries/invoicing/useUnprocessedPayments.js';
|
|
451
465
|
export * from './api/queries/invoicing/useUpcomingInvoicing.js';
|
|
466
|
+
export * from './api/queries/invoicing/usePlannedInvoicePreviews.js';
|
|
467
|
+
export * from './api/queries/utilityUsage/useUtilityUsage.js';
|
|
452
468
|
export * from './api/queries/issue/useIssue.js';
|
|
453
469
|
export * from './api/queries/issue/useIssues.js';
|
|
454
470
|
export * from './api/queries/meeting/useMeetings.js';
|
package/dist/index.js
CHANGED
|
@@ -2,9 +2,20 @@ import './utils/bigint-polyfill.js';
|
|
|
2
2
|
// React-specific exports
|
|
3
3
|
export { SoliboProvider, SdkProvider, useSoliboApi, useSdk, SoliboContext, createSdk, } from './sdkProvider.js';
|
|
4
4
|
export { useMutation } from './utils/useMutation.js';
|
|
5
|
+
export { DEFAULT_PAGE_SIZE, MAX_PAGE_SIZE, useAllPages, usePagedItems, } from './utils/pages.js';
|
|
6
|
+
export { useByteArrayUrl } from './utils/useByteArrayUrl.js';
|
|
7
|
+
export * from './api/queries/user/useCompanyActions.js';
|
|
8
|
+
export * from './api/queries/document/useDocumentURL.js';
|
|
9
|
+
export * from './api/queries/company/useCompanyNames.js';
|
|
10
|
+
export * from './api/queries/countries/useCountryLookup.js';
|
|
11
|
+
export * from './api/commands/homepage/useDeleteHomepageImage.js';
|
|
12
|
+
export * from './api/commands/conversation/useConversationHelpers.js';
|
|
13
|
+
export * from './api/commands/resident/useUpdateResidentContact.js';
|
|
14
|
+
export * from './api/commands/document/useOwnedDocumentMutations.js';
|
|
5
15
|
export { useOpenApiOperationMutation, useOpenApiOperationQuery, } from './api/useOpenApiOperation.js';
|
|
6
16
|
export * from './api/commands/board/useCreateBoardMember.js';
|
|
7
17
|
export * from './api/commands/board/useDeleteBoardMember.js';
|
|
18
|
+
export * from './api/commands/board/useSetBoardMemberTerm.js';
|
|
8
19
|
export * from './api/commands/board/useInviteBoardMemberToSoliboHome.js';
|
|
9
20
|
export * from './api/commands/communication/useBuySMSBundle.js';
|
|
10
21
|
export * from './api/commands/communication/useCreateNewsletter.js';
|
|
@@ -96,12 +107,14 @@ export * from './api/commands/document/useUpdateDocument.js';
|
|
|
96
107
|
export * from './api/commands/document/useTrashMultipleDocuments.js';
|
|
97
108
|
export * from './api/commands/document/useUploadDocument.js';
|
|
98
109
|
export * from './api/commands/document/useIntegratedDocumentMutations.js';
|
|
110
|
+
export * from './api/commands/document/useIntegratedRetry.js';
|
|
99
111
|
export * from './api/commands/economy/useApproveInvoice.js';
|
|
100
112
|
export * from './api/commands/economy/useAttachDocumentToEconomicReport.js';
|
|
101
113
|
export * from './api/commands/economy/useCreateInvoiceNotice.js';
|
|
102
114
|
export * from './api/commands/economy/useDeleteEconomicReport.js';
|
|
103
115
|
export * from './api/commands/economy/useOrderEconomicReport.js';
|
|
104
116
|
export * from './api/commands/economy/useRejectInvoice.js';
|
|
117
|
+
export * from './api/commands/economy/useCreateInvoiceComment.js';
|
|
105
118
|
export * from './api/commands/economy/useUpdateInvoiceNotification.js';
|
|
106
119
|
export * from './api/commands/economy/useUpdateRealtimeInvoiceNotification.js';
|
|
107
120
|
export * from './api/commands/expense/useApproveExpense.js';
|
|
@@ -447,6 +460,8 @@ export * from './api/queries/invoicing/useSectionInvoices.js';
|
|
|
447
460
|
export * from './api/queries/invoicing/useSectionInvoicesQueries.js';
|
|
448
461
|
export * from './api/queries/invoicing/useUnprocessedPayments.js';
|
|
449
462
|
export * from './api/queries/invoicing/useUpcomingInvoicing.js';
|
|
463
|
+
export * from './api/queries/invoicing/usePlannedInvoicePreviews.js';
|
|
464
|
+
export * from './api/queries/utilityUsage/useUtilityUsage.js';
|
|
450
465
|
export * from './api/queries/issue/useIssue.js';
|
|
451
466
|
export * from './api/queries/issue/useIssues.js';
|
|
452
467
|
export * from './api/queries/meeting/useMeetings.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useSharedText, type SharedTextCollaboration, type SharedTextEditor, type UseSharedTextOptions, } from './useSharedText.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useSharedText, } from './useSharedText.js';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import '@solibo/solibo-sdk/events';
|
|
2
|
+
import { SharedTextProvider, type SharedTextOwnerType, type SharedTextProblem } from '@solibo/solibo-query/shared-text';
|
|
3
|
+
import { Doc } from 'yjs';
|
|
4
|
+
/** The person editing, as the signed-in user's profile describes them. */
|
|
5
|
+
export type SharedTextEditor = {
|
|
6
|
+
id: string;
|
|
7
|
+
name?: {
|
|
8
|
+
complete?: string | null;
|
|
9
|
+
} | null;
|
|
10
|
+
username?: string | null;
|
|
11
|
+
};
|
|
12
|
+
export type UseSharedTextOptions = {
|
|
13
|
+
companyId: bigint | number | null | undefined;
|
|
14
|
+
ownerType: SharedTextOwnerType;
|
|
15
|
+
/** Null while the owner is being created: a text is only shared once its owner exists. */
|
|
16
|
+
ownerId: bigint | number | null | undefined;
|
|
17
|
+
editor: SharedTextEditor | null | undefined;
|
|
18
|
+
/** False keeps the body an ordinary text, for example while a feature switch is off. */
|
|
19
|
+
enabled?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* The body was replaced by someone outside the shared text, such as a form or an API client.
|
|
22
|
+
* The editor has already started over from the new body; tell the person why it changed.
|
|
23
|
+
*/
|
|
24
|
+
onReplaced?: () => void;
|
|
25
|
+
/**
|
|
26
|
+
* Editing together stopped for this owner, and the body is edited on its own again from what
|
|
27
|
+
* the editor shows: the person may not edit the shared text, it has no content yet, or it did
|
|
28
|
+
* not arrive. Tell the person that others' typing no longer reaches them.
|
|
29
|
+
*/
|
|
30
|
+
onUnavailable?: (problem: SharedTextProblem) => void;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* The `collaboration` prop of the solibo-ui editor. The editor picks each person's cursor colour
|
|
34
|
+
* from their name.
|
|
35
|
+
*/
|
|
36
|
+
export type SharedTextCollaboration = {
|
|
37
|
+
id: string;
|
|
38
|
+
providerFactory: (id: string, documents: Map<string, Doc>) => SharedTextProvider;
|
|
39
|
+
username: string;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Edits an owner's rich-text body together with everyone else who has it open, over the event
|
|
43
|
+
* bus. Returns what the solibo-ui editor takes as `collaboration`, or undefined when the body is
|
|
44
|
+
* to be edited on its own: when [enabled] is false, there is no owner or editor yet, or the person
|
|
45
|
+
* may not edit the shared text or it has no content yet. Then the editor edits its `content` as
|
|
46
|
+
* before.
|
|
47
|
+
*/
|
|
48
|
+
export declare const useSharedText: ({ companyId, ownerType, ownerId, editor, enabled, onReplaced, onUnavailable, }: UseSharedTextOptions) => SharedTextCollaboration | undefined;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import '@solibo/solibo-sdk/events';
|
|
2
|
+
import { createSharedTextTransport, SharedTextProvider, } from '@solibo/solibo-query/shared-text';
|
|
3
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
4
|
+
import { Doc } from 'yjs';
|
|
5
|
+
import { useSdk } from '../sdkProvider.js';
|
|
6
|
+
/**
|
|
7
|
+
* Edits an owner's rich-text body together with everyone else who has it open, over the event
|
|
8
|
+
* bus. Returns what the solibo-ui editor takes as `collaboration`, or undefined when the body is
|
|
9
|
+
* to be edited on its own: when [enabled] is false, there is no owner or editor yet, or the person
|
|
10
|
+
* may not edit the shared text or it has no content yet. Then the editor edits its `content` as
|
|
11
|
+
* before.
|
|
12
|
+
*/
|
|
13
|
+
export const useSharedText = ({ companyId, ownerType, ownerId, editor, enabled = true, onReplaced, onUnavailable, }) => {
|
|
14
|
+
const sdk = useSdk();
|
|
15
|
+
const onUnavailableRef = useRef(onUnavailable);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
onUnavailableRef.current = onUnavailable;
|
|
18
|
+
}, [onUnavailable]);
|
|
19
|
+
const [round, setRound] = useState(0);
|
|
20
|
+
const owner = `${ownerType}:${companyId}:${ownerId}`;
|
|
21
|
+
const [unavailableFor, setUnavailableFor] = useState(null);
|
|
22
|
+
const unavailable = unavailableFor === owner;
|
|
23
|
+
const providerFactory = useCallback((id, documents) => {
|
|
24
|
+
const document = documents.get(id) ?? new Doc();
|
|
25
|
+
documents.set(id, document);
|
|
26
|
+
const provider = new SharedTextProvider(document, createSharedTextTransport(sdk.eventBus), {
|
|
27
|
+
companyId: Number(companyId),
|
|
28
|
+
ownerId: Number(ownerId),
|
|
29
|
+
ownerType,
|
|
30
|
+
});
|
|
31
|
+
provider.on('problem', ((problem) => {
|
|
32
|
+
if (problem === 'REPLACED') {
|
|
33
|
+
onReplaced?.();
|
|
34
|
+
setRound((current) => current + 1);
|
|
35
|
+
}
|
|
36
|
+
else if (problem !== 'TOO_LARGE') {
|
|
37
|
+
setUnavailableFor(owner);
|
|
38
|
+
onUnavailableRef.current?.(problem);
|
|
39
|
+
}
|
|
40
|
+
}));
|
|
41
|
+
return provider;
|
|
42
|
+
}, [companyId, onReplaced, owner, ownerId, ownerType, sdk]);
|
|
43
|
+
if (!enabled ||
|
|
44
|
+
unavailable ||
|
|
45
|
+
!editor ||
|
|
46
|
+
companyId == null ||
|
|
47
|
+
ownerId == null) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
id: `${ownerType}:${ownerId}:${round}`,
|
|
52
|
+
providerFactory,
|
|
53
|
+
username: editor.name?.complete ?? editor.username ?? '',
|
|
54
|
+
};
|
|
55
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { FetchNextPageOptions } from '@tanstack/react-query';
|
|
2
|
+
/** The page size a list asks for when it shows one page at a time. */
|
|
3
|
+
export declare const DEFAULT_PAGE_SIZE = 20;
|
|
4
|
+
/** The largest page the backend serves; ask for it when a list must load every item. */
|
|
5
|
+
export declare const MAX_PAGE_SIZE = 1000;
|
|
6
|
+
/** The data of a paged infinite query: pages with optional `items`. */
|
|
7
|
+
export interface PagedQueryData<T> {
|
|
8
|
+
pages: ReadonlyArray<{
|
|
9
|
+
readonly items?: readonly T[] | null;
|
|
10
|
+
} | null | undefined>;
|
|
11
|
+
}
|
|
12
|
+
/** The items of every page loaded so far, in order. Stable while the pages are unchanged. */
|
|
13
|
+
export declare function usePagedItems<T>(data: PagedQueryData<T> | null | undefined): T[];
|
|
14
|
+
/** What useAllPages needs of an infinite query result. */
|
|
15
|
+
export interface AllPagesQuery<T> {
|
|
16
|
+
data?: PagedQueryData<T> | null;
|
|
17
|
+
fetchNextPage: (options?: FetchNextPageOptions) => Promise<unknown>;
|
|
18
|
+
hasNextPage?: boolean;
|
|
19
|
+
isFetchingNextPage?: boolean;
|
|
20
|
+
isFetching?: boolean;
|
|
21
|
+
isPending?: boolean;
|
|
22
|
+
isSuccess?: boolean;
|
|
23
|
+
isError?: boolean;
|
|
24
|
+
error?: unknown;
|
|
25
|
+
}
|
|
26
|
+
export interface AllPagesResult<T> {
|
|
27
|
+
/** The items of every page loaded so far. */
|
|
28
|
+
items: T[];
|
|
29
|
+
/** True once every page has loaded. */
|
|
30
|
+
isComplete: boolean;
|
|
31
|
+
/** True while the first page or any later page is still loading. */
|
|
32
|
+
isPending: boolean;
|
|
33
|
+
isError: boolean;
|
|
34
|
+
error: unknown;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Loads every page of a paged infinite query, one after the other, and returns their items. Use it
|
|
38
|
+
* where a screen needs the whole collection (a permission check, a select box); pass a large
|
|
39
|
+
* `count` (up to MAX_PAGE_SIZE) to the query to keep the number of requests down. Loading stops at
|
|
40
|
+
* the first error and goes on when the query is retried.
|
|
41
|
+
*/
|
|
42
|
+
export declare function useAllPages<T>(query: AllPagesQuery<T>, enabled?: boolean): AllPagesResult<T>;
|