mirror of
https://github.com/documenso/documenso.git
synced 2025-11-14 00:32:43 +10:00
## Description Adds the ability for the document owner to edit recipients and their fields after the document has been sent. A recipient can only be updated or deleted if: - The recipient has not inserted any fields - Has not completed the document <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes - **New Features** - Added new localization messages to clarify user actions regarding document signing. - Enhanced French translations for improved user interaction. - **Improvements** - Updated localization strings in German and English for clearer feedback on signer and recipient statuses. - Improved overall structure of localization files for better maintainability. - **Dependency Updates** - Upgraded `next-axiom` and `remeda` libraries to their latest versions, potentially enhancing performance and stability. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Mythie <me@lucasjamessmith.me>
80 lines
1.7 KiB
TypeScript
80 lines
1.7 KiB
TypeScript
'use client';
|
|
|
|
import { createContext, useCallback, useContext, useEffect, useState } from 'react';
|
|
|
|
import { isDeepEqual } from 'remeda';
|
|
|
|
import { getLimits } from '../client';
|
|
import { FREE_PLAN_LIMITS } from '../constants';
|
|
import type { TLimitsResponseSchema } from '../schema';
|
|
|
|
export type LimitsContextValue = TLimitsResponseSchema & { refreshLimits: () => Promise<void> };
|
|
|
|
const LimitsContext = createContext<LimitsContextValue | null>(null);
|
|
|
|
export const useLimits = () => {
|
|
const limits = useContext(LimitsContext);
|
|
|
|
if (!limits) {
|
|
throw new Error('useLimits must be used within a LimitsProvider');
|
|
}
|
|
|
|
return limits;
|
|
};
|
|
|
|
export type LimitsProviderProps = {
|
|
initialValue?: TLimitsResponseSchema;
|
|
teamId?: number;
|
|
children?: React.ReactNode;
|
|
};
|
|
|
|
export const LimitsProvider = ({
|
|
initialValue = {
|
|
quota: FREE_PLAN_LIMITS,
|
|
remaining: FREE_PLAN_LIMITS,
|
|
},
|
|
teamId,
|
|
children,
|
|
}: LimitsProviderProps) => {
|
|
const [limits, setLimits] = useState(() => initialValue);
|
|
|
|
const refreshLimits = useCallback(async () => {
|
|
const newLimits = await getLimits({ teamId });
|
|
|
|
setLimits((oldLimits) => {
|
|
if (isDeepEqual(oldLimits, newLimits)) {
|
|
return oldLimits;
|
|
}
|
|
|
|
return newLimits;
|
|
});
|
|
}, [teamId]);
|
|
|
|
useEffect(() => {
|
|
void refreshLimits();
|
|
}, [refreshLimits]);
|
|
|
|
useEffect(() => {
|
|
const onFocus = () => {
|
|
void refreshLimits();
|
|
};
|
|
|
|
window.addEventListener('focus', onFocus);
|
|
|
|
return () => {
|
|
window.removeEventListener('focus', onFocus);
|
|
};
|
|
}, [refreshLimits]);
|
|
|
|
return (
|
|
<LimitsContext.Provider
|
|
value={{
|
|
...limits,
|
|
refreshLimits,
|
|
}}
|
|
>
|
|
{children}
|
|
</LimitsContext.Provider>
|
|
);
|
|
};
|