feat(MED-97): small fixes
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { getSupabaseServerClient } from "@/packages/supabase/src/clients/server-client";
|
import { getSupabaseServerClient } from "@/packages/supabase/src/clients/server-client";
|
||||||
import { loadAccountBenefitStatistics, loadCompanyPersonalAccountsBalanceEntries } from "./load-team-account-benefit-statistics";
|
import { loadCompanyPersonalAccountsBalanceEntries } from "./load-team-account-benefit-statistics";
|
||||||
|
|
||||||
export interface TeamAccountBenefitExpensesOverview {
|
export interface TeamAccountBenefitExpensesOverview {
|
||||||
benefitAmount: number | null;
|
benefitAmount: number | null;
|
||||||
@@ -65,7 +65,7 @@ export async function loadTeamAccountBenefitExpensesOverview({
|
|||||||
return benefitAmount * employeeCount * monthsLeft;
|
return benefitAmount * employeeCount * monthsLeft;
|
||||||
} else if (benefitOccurrence === 'quarterly') {
|
} else if (benefitOccurrence === 'quarterly') {
|
||||||
const quartersLeft = isCreatedThisYear
|
const quartersLeft = isCreatedThisYear
|
||||||
? QUARTERS - (createdAt.getMonth() / 3)
|
? QUARTERS - Math.ceil(createdAt.getMonth() / 3)
|
||||||
: QUARTERS;
|
: QUARTERS;
|
||||||
return benefitAmount * employeeCount * quartersLeft;
|
return benefitAmount * employeeCount * quartersLeft;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,8 +73,7 @@ export const loadAccountBenefitStatistics = async (
|
|||||||
.select('*')
|
.select('*')
|
||||||
.eq('company_id', accountId)
|
.eq('company_id', accountId)
|
||||||
.eq('is_active', true)
|
.eq('is_active', true)
|
||||||
.single()
|
.single();
|
||||||
.throwOnError();
|
|
||||||
|
|
||||||
const scheduleAmount = benefitDistributionSchedule?.benefit_amount || 0;
|
const scheduleAmount = benefitDistributionSchedule?.benefit_amount || 0;
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
|
||||||
import { UpdateHealthBenefitSchema } from '@/packages/billing/core/src/schema';
|
import { UpdateHealthBenefitSchema } from '@/packages/billing/core/src/schema';
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
@@ -27,6 +28,7 @@ const HealthBenefitFormClient = ({
|
|||||||
companyParams: CompanyParams;
|
companyParams: CompanyParams;
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation('account');
|
const { t } = useTranslation('account');
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
const [currentCompanyParams, setCurrentCompanyParams] =
|
const [currentCompanyParams, setCurrentCompanyParams] =
|
||||||
useState<CompanyParams>(companyParams);
|
useState<CompanyParams>(companyParams);
|
||||||
@@ -56,6 +58,7 @@ const HealthBenefitFormClient = ({
|
|||||||
} finally {
|
} finally {
|
||||||
form.reset(data);
|
form.reset(data);
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
|
router.refresh();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -32,8 +32,8 @@ const HealthBenefitForm = async ({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex flex-row gap-6">
|
<div className="flex flex-col-reverse sm:flex-row gap-6">
|
||||||
<div className="border-border w-1/3 rounded-lg border">
|
<div className="border-border w-full sm:w-1/3 rounded-lg border">
|
||||||
<div className="p-6">
|
<div className="p-6">
|
||||||
<div className="flex h-16 w-16 items-center justify-center rounded-full bg-orange-100">
|
<div className="flex h-16 w-16 items-center justify-center rounded-full bg-orange-100">
|
||||||
<PiggyBankIcon className="h-[32px] w-[32px] stroke-orange-400 stroke-2" />
|
<PiggyBankIcon className="h-[32px] w-[32px] stroke-orange-400 stroke-2" />
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ async function JoinTeamAccountPage(props: JoinTeamAccountPageProps) {
|
|||||||
return (
|
return (
|
||||||
<AuthLayoutShell Logo={AppLogo}>
|
<AuthLayoutShell Logo={AppLogo}>
|
||||||
<AcceptInvitationContainer
|
<AcceptInvitationContainer
|
||||||
fullName={fullName}
|
fullName={fullName || auth.data.email || ''}
|
||||||
inviteToken={token}
|
inviteToken={token}
|
||||||
invitation={invitation}
|
invitation={invitation}
|
||||||
paths={{
|
paths={{
|
||||||
|
|||||||
@@ -115,11 +115,13 @@ export class AccountBalanceService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async processPeriodicBenefitDistributions(): Promise<void> {
|
async processPeriodicBenefitDistributions(): Promise<void> {
|
||||||
const { error } = await this.supabase.schema('medreport').rpc('process_periodic_benefit_distributions')
|
console.info('Processing periodic benefit distributions...');
|
||||||
|
const { error } = await this.supabase.schema('medreport').rpc('process_periodic_benefit_distributions');
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error('Error processing periodic benefit distributions:', error);
|
console.error('Error processing periodic benefit distributions:', error);
|
||||||
throw new Error('Failed to process periodic benefit distributions');
|
throw new Error('Failed to process periodic benefit distributions');
|
||||||
}
|
}
|
||||||
|
console.info('Periodic benefit distributions processed successfully');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -149,6 +149,7 @@ export const updateInvitationAction = enhanceAction(
|
|||||||
export const acceptInvitationAction = enhanceAction(
|
export const acceptInvitationAction = enhanceAction(
|
||||||
async (data: FormData, user) => {
|
async (data: FormData, user) => {
|
||||||
const client = getSupabaseServerClient();
|
const client = getSupabaseServerClient();
|
||||||
|
const accountBalanceService = new AccountBalanceService();
|
||||||
|
|
||||||
const { inviteToken, nextPath } = AcceptInvitationSchema.parse(
|
const { inviteToken, nextPath } = AcceptInvitationSchema.parse(
|
||||||
Object.fromEntries(data),
|
Object.fromEntries(data),
|
||||||
@@ -173,7 +174,7 @@ export const acceptInvitationAction = enhanceAction(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Make sure new account gets company benefits added to balance
|
// Make sure new account gets company benefits added to balance
|
||||||
await new AccountBalanceService().processPeriodicBenefitDistributions();
|
await accountBalanceService.processPeriodicBenefitDistributions();
|
||||||
|
|
||||||
// Increase the seats for the account
|
// Increase the seats for the account
|
||||||
await perSeatBillingService.increaseSeats(accountId);
|
await perSeatBillingService.increaseSeats(accountId);
|
||||||
|
|||||||
Reference in New Issue
Block a user