Skip to content
Closed
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
20 changes: 1 addition & 19 deletions app/client/src/components/forms/ConfigForm.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import Button from '$components/common/Button.svelte';
import { currencyOptions, dateFormatOptions, uomOptions } from '$lib/models/config';

let { modalVisibility = $bindable(), loading = false, callback } = $props();

Expand All @@ -15,25 +16,6 @@

let localConfig: Config[] = $state([]);

const dateFormatOptions = [
{ value: 'dd/MM/yyyy', label: 'dd/MM/yyyy (e.g., 31/12/2000)' },
{ value: 'MM/dd/yyyy', label: 'MM/dd/yyyy (e.g., 12/25/2000)' },
{ value: 'yyyy-MM-dd', label: 'yyyy-MM-dd (e.g., 2000-12-31)' },
{ value: 'dd MMM, yyyy', label: 'dd MMM, yyyy (e.g., 31 Dec, 2000)' }
];

const currencyOptions = [
{ value: 'INR', label: 'INR (₹)' },
{ value: 'USD', label: 'USD ($)' },
{ value: 'EUR', label: 'EUR (€)' },
{ value: 'GBP', label: 'GBP (£)' }
];

const uomOptions = [
{ value: 'metric', label: 'Metric' },
{ value: 'imperial', label: 'Imperial' }
];

config.subscribe((value) => {
localConfig = JSON.parse(JSON.stringify(value));
});
Expand Down
19 changes: 19 additions & 0 deletions app/client/src/lib/models/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export const dateFormatOptions = [
{ value: 'dd/MM/yyyy', label: 'dd/MM/yyyy (e.g., 31/12/2000)' },
{ value: 'MM/dd/yyyy', label: 'MM/dd/yyyy (e.g., 12/25/2000)' },
{ value: 'yyyy-MM-dd', label: 'yyyy-MM-dd (e.g., 2000-12-31)' },
{ value: 'dd MMM, yyyy', label: 'dd MMM, yyyy (e.g., 31 Dec, 2000)' }
];

export const currencyOptions = [
{ value: 'INR', label: 'INR (₹)', symbol: '₹' },
{ value: 'USD', label: 'USD ($)', symbol: '$' },
{ value: 'EUR', label: 'EUR (€)', symbol: '€' },
{ value: 'GBP', label: 'GBP (£)', symbol: '£' },
{ value: 'CHF', label: 'CHF (₣)', symbol: '₣' }
];

export const uomOptions = [
{ value: 'metric', label: 'Metric' },
{ value: 'imperial', label: 'Imperial' }
];
16 changes: 4 additions & 12 deletions app/client/src/lib/utils/formatting.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { currencyOptions } from '$lib/models/config';
import { config } from '$lib/stores/config';
import { format } from 'date-fns';

Expand Down Expand Up @@ -32,21 +33,12 @@ const formatDate = (date: Date | string): string => {
};

const getCurrencySymbol = (): string => {
return (
new Intl.NumberFormat('en-US', {
style: 'currency',
currency: configs.currency
})
.formatToParts(0)
.find((part) => part.type === 'currency')?.value || ''
);
return currencyOptions.find((currency) => configs.currency == currency.value)?.symbol || ''
};

const formatCurrency = (amount: number): string => {
return new Intl.NumberFormat('en-US', {
style: 'currency',
currency: configs.currency
}).format(amount);
const formattedAmount = new Intl.NumberFormat('en-US').format(amount);
return `${getCurrencySymbol()} ${formattedAmount}`;
};

const getDistanceUnit = (): string => {
Expand Down