Skip to content

add configuration for benefits payment period boundaries #232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions frontend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ OTEL_USE_CONSOLE_TRACE_EXPORTER=
# Estimator configuration
#################################################

# Benefits payments period start date shown on index page (YYYY-MM-DD)
ESTIMATOR_CDB_BENEFIT_PAYMENT_PERIOD_START=

# Benefits payments period end date shown on index page (YYYY-MM-DD)
ESTIMATOR_CDB_BENEFIT_PAYMENT_PERIOD_END=

# Canada Disability Benefit english contact URL
ESTIMATOR_CDB_CONTACT_URL_EN=

Expand Down
17 changes: 17 additions & 0 deletions frontend/app/.server/environment/estimator.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import * as v from 'valibot';

import { stringToBooleanSchema } from '../validation/string-to-boolean-schema';
import { stringToIsoDateSchema } from '../validation/string-to-iso-date-schema';
import { stringToNumberSchema } from '../validation/string-to-number-schema';
import { stringToUrlSchema } from '../validation/string-to-url-schema';

// Default estimator configuration object
export const defaults = {
ESTIMATOR_CDB_BENEFIT_PAYMENT_PERIOD_START: '2025-07-01',
ESTIMATOR_CDB_BENEFIT_PAYMENT_PERIOD_END: '2026-06-01',
ESTIMATOR_CDB_CONTACT_URL_EN: undefined,
ESTIMATOR_CDB_CONTACT_URL_FR: undefined,
ESTIMATOR_CDB_URL_EN: 'https://www.canada.ca/en/services/benefits/disability/canada-disability-benefit.html',
Expand All @@ -30,6 +33,20 @@ export const defaults = {

// Define schema for the environment variable
export const estimator = v.object({
/**
* Benefits payments period start date shown on index page (YYYY-MM-DD)
*/
ESTIMATOR_CDB_BENEFIT_PAYMENT_PERIOD_START: v.optional(
stringToIsoDateSchema(),
defaults.ESTIMATOR_CDB_BENEFIT_PAYMENT_PERIOD_START,
),
/**
* Benefits payments period end date shown on index page (YYYY-MM-DD)
*/
ESTIMATOR_CDB_BENEFIT_PAYMENT_PERIOD_END: v.optional(
stringToIsoDateSchema(),
defaults.ESTIMATOR_CDB_BENEFIT_PAYMENT_PERIOD_END,
),
/**
* Canada Disability Benefit english contact URL
*/
Expand Down
1 change: 1 addition & 0 deletions frontend/app/.server/locales/estimator-en.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
"result-disclaimer": "<strong>This tool provides an estimate only. It doesn't guarantee that you'll be eligible or that you'll receive the amount estimated.</strong>",
"results": {
"contact": " For a more accurate assessment of your estimated benefits amount, please <cdbContactLink>contact us</cdbContactLink>.",
"description": "This estimator provides estimated benefit amounts for payments made between {{paymentPeriodStart}} and {{paymentPeriodEnd}}. Future benefit amounts may be higher. The results are not financial advice and are subject to change.",
"description": "This estimator provides estimated benefit amounts for payments made between July 2025 and June 2026. Future benefit amounts may be higher. The results are not financial advice and are subject to change.",
"header": "About the results"
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/.server/locales/estimator-fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
"result-disclaimer": "<strong>Cet outil fournit une estimation seulement. Il ne garantit pas que vous serez admissible ou que vous recevrez le montant estimé.</strong>",
"results": {
"contact": " Pour une évaluation plus précise de votre montant de prestations estimé, veuillez <cdbContactLink>communiquer avec nous</cdbContactLink>.",
"description": "Cet estimateur fournit des montants estimés de prestation pour les paiements effectués entre juillet 2025 et juin 2026. Les montants des prestations futures pourraient être plus élevés en raison de l'inflation. Les résultats ne sont pas des conseils financiers et peuvent changer.",
"description": "Cet estimateur fournit des montants estimés de prestation pour les paiements effectués entre {{paymentPeriodStart}} et {{paymentPeriodEnd}}. Les montants des prestations futures pourraient être plus élevés en raison de l'inflation. Les résultats ne sont pas des conseils financiers et peuvent changer.",
"header": "À propos des résultats"
}
},
Expand Down
5 changes: 5 additions & 0 deletions frontend/app/.server/validation/string-to-iso-date-schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import * as v from 'valibot';

export function stringToIsoDateSchema(): v.GenericSchema<string, string> {
return v.pipe(v.string(), v.isoDate());
}
23 changes: 22 additions & 1 deletion frontend/app/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,21 @@ export async function loader({ request }: Route.LoaderArgs) {
};
}

function formatBenefitPaymentsPeriodDate(date: Date, lang: 'fr' | 'en' | undefined) {
const options: Intl.DateTimeFormatOptions = {
year: 'numeric',
month: 'long',
timeZone: 'UTC',
};

return date.toLocaleDateString(lang === 'fr' ? 'fr-CA' : 'en-CA', options);
}

export default function Home({ loaderData }: Route.ComponentProps) {
const { t, i18n } = useTranslation(handle.i18nNamespace);
const {
ESTIMATOR_CDB_BENEFIT_PAYMENT_PERIOD_START,
ESTIMATOR_CDB_BENEFIT_PAYMENT_PERIOD_END,
ESTIMATOR_CDB_CONTACT_URL_EN,
ESTIMATOR_CDB_CONTACT_URL_FR,
ESTIMATOR_CDB_ELIGIBILITY_URL_EN,
Expand Down Expand Up @@ -106,7 +118,16 @@ export default function Home({ loaderData }: Route.ComponentProps) {
<section className="space-y-4">
<h2 className="font-lato text-lg font-bold">{t('estimator:index.content.results.header')}</h2>
<p>
<Trans ns={handle.i18nNamespace} i18nKey="estimator:index.content.results.description" />
{t('estimator:index.content.results.description', {
paymentPeriodStart: formatBenefitPaymentsPeriodDate(
new Date(ESTIMATOR_CDB_BENEFIT_PAYMENT_PERIOD_START),
i18n.language,
),
paymentPeriodEnd: formatBenefitPaymentsPeriodDate(
new Date(ESTIMATOR_CDB_BENEFIT_PAYMENT_PERIOD_END),
i18n.language,
),
})}

{i18n.language === 'fr' && ESTIMATOR_CDB_CONTACT_URL_FR && (
<Trans
Expand Down