33 lines
845 B
JavaScript
33 lines
845 B
JavaScript
import { StoreContext } from '.';
|
|
import { useContext } from 'react';
|
|
|
|
export function useStore() {
|
|
const context = useContext(StoreContext);
|
|
if (context === undefined) {
|
|
throw new Error('useStore must be used within StoreProvider');
|
|
}
|
|
|
|
return context;
|
|
}
|
|
|
|
export function useErrors() {
|
|
const { $calculation, $tables } = useStore();
|
|
|
|
const hasElementsErrors = $calculation.hasErrors;
|
|
const hasPaymentsErrors = $tables.payments.validation.hasErrors;
|
|
const hasInsuranceErrors = $tables.insurance.validation.hasErrors;
|
|
const hasFingapErrors = $tables.fingap.validation.hasErrors;
|
|
|
|
return {
|
|
hasErrors: hasElementsErrors || hasPaymentsErrors || hasInsuranceErrors || hasFingapErrors,
|
|
};
|
|
}
|
|
|
|
export function useResults() {
|
|
const { $results } = useStore();
|
|
|
|
return {
|
|
hasResults: $results.payments.length > 0,
|
|
};
|
|
}
|