From 75a78cdda5856fde6a9ab96923b0449d305757e5 Mon Sep 17 00:00:00 2001 From: aelassas Date: Tue, 16 Apr 2024 12:02:43 +0100 Subject: [PATCH] Update currency and price formats --- backend/src/common/helper.ts | 21 ++++++----- backend/src/components/BookingList.tsx | 6 ++-- backend/src/components/PropertyInfo.tsx | 8 +++-- backend/src/components/PropertyList.tsx | 3 +- backend/src/lang/common.ts | 4 +-- backend/src/pages/Property.tsx | 7 ++-- backend/src/pages/PropertyBookings.tsx | 34 ++++++++++-------- backend/src/pages/UpdateBooking.tsx | 8 +++-- frontend/src/common/helper.ts | 21 ++++++----- frontend/src/components/BookingList.tsx | 6 ++-- frontend/src/components/PropertyInfo.tsx | 9 +++-- frontend/src/components/PropertyList.tsx | 7 ++-- frontend/src/lang/common.ts | 4 +-- frontend/src/pages/Booking.tsx | 8 +++-- frontend/src/pages/Checkout.tsx | 8 ++--- frontend/src/pages/Property.tsx | 5 ++- frontend/src/pages/Search.tsx | 5 +++ mobile/common/helper.ts | 21 ++++++----- mobile/components/Booking.tsx | 10 +++--- mobile/components/BookingList.tsx | 3 +- mobile/components/Property.tsx | 12 +++---- mobile/components/PropertyList.tsx | 3 +- mobile/lang/en.ts | 2 +- mobile/lang/fr.ts | 2 +- mobile/screens/Checkout.tsx | 8 ++--- packages/movinin-helper/index.ts | 44 +++++++++++++++++++----- 26 files changed, 170 insertions(+), 99 deletions(-) diff --git a/backend/src/common/helper.ts b/backend/src/common/helper.ts index 13dc4359..5cd1e4b1 100644 --- a/backend/src/common/helper.ts +++ b/backend/src/common/helper.ts @@ -310,33 +310,37 @@ export const getDaysShort = (days: number) => `${days} ${strings.PRICE_DAYS_PART * Get cancellation label. * * @param {number} cancellation - * @param {boolean} fr + * @param {string} language * @returns {string} */ -export const getCancellation = (cancellation: number, fr: boolean) => { +export const getCancellation = (cancellation: number, language: string) => { + const fr = movininHelper.isFrench(language) + if (cancellation === -1) { return `${strings.CANCELLATION}${fr ? ' : ' : ': '}${strings.UNAVAILABLE}` } if (cancellation === 0) { return `${strings.CANCELLATION}${fr ? ' : ' : ': '}${strings.INCLUDED}${fr ? 'e' : ''}` } - return `${strings.CANCELLATION}${fr ? ' : ' : ': '}${movininHelper.formatNumber(cancellation)} ${commonStrings.CURRENCY}` + return `${strings.CANCELLATION}${fr ? ' : ' : ': '}${movininHelper.formatPrice(cancellation, commonStrings.CURRENCY, language)}` } /** * Get cancellation option label. * * @param {number} cancellation - * @param {boolean} fr + * @param {string} language * @param {boolean} hidePlus * @returns {string} */ -export const getCancellationOption = (cancellation: number, fr: boolean, hidePlus: boolean) => { +export const getCancellationOption = (cancellation: number, language: string, hidePlus: boolean) => { + const fr = movininHelper.isFrench(language) + if (cancellation === -1) { return strings.UNAVAILABLE } if (cancellation === 0) { return `${strings.INCLUDED}${fr ? 'e' : ''}` } - return `${hidePlus ? '' : '+ '}${cancellation} ${commonStrings.CURRENCY}` + return `${hidePlus ? '' : '+ '}${movininHelper.formatPrice(cancellation, commonStrings.CURRENCY, language)}` } /** @@ -433,7 +437,8 @@ export const rentalTermUnit = (term: movininTypes.RentalTerm): string => { * Get price label. * * @param {movininTypes.Property} property + * @param {string} language * @returns {string} */ -export const priceLabel = (property: movininTypes.Property): string => - `${movininHelper.formatNumber(property.price)} ${commonStrings.CURRENCY}/${rentalTermUnit(property.rentalTerm)}` +export const priceLabel = (property: movininTypes.Property, language: string): string => + `${movininHelper.formatPrice(property.price, commonStrings.CURRENCY, language)}/${rentalTermUnit(property.rentalTerm)}` diff --git a/backend/src/components/BookingList.tsx b/backend/src/components/BookingList.tsx index 8e27fdaf..f891eee5 100644 --- a/backend/src/components/BookingList.tsx +++ b/backend/src/components/BookingList.tsx @@ -243,7 +243,7 @@ const BookingList = ({ headerName: strings.PRICE, flex: 1, renderCell: ({ value }: GridRenderCellParams) => {value}, - valueGetter: (value: number) => `${movininHelper.formatNumber(value)} ${commonStrings.CURRENCY}`, + valueGetter: (value: number) => movininHelper.formatPrice(value, commonStrings.CURRENCY, language as string), }, { field: 'status', @@ -550,7 +550,7 @@ const BookingList = ({
{csStrings.CANCELLATION} - {helper.getCancellationOption((booking.property as movininTypes.Property).cancellation, _fr, true)} + {helper.getCancellationOption((booking.property as movininTypes.Property).cancellation, language as string, true)}
)} @@ -560,7 +560,7 @@ const BookingList = ({
{strings.COST} -
{`${movininHelper.formatNumber(booking.price)} ${commonStrings.CURRENCY}`}
+
{movininHelper.formatPrice(booking.price as number, commonStrings.CURRENCY, language as string)}
diff --git a/backend/src/components/PropertyInfo.tsx b/backend/src/components/PropertyInfo.tsx index 541c38e8..cdee4260 100644 --- a/backend/src/components/PropertyInfo.tsx +++ b/backend/src/components/PropertyInfo.tsx @@ -36,6 +36,7 @@ interface PropertyInfoProps { booking?: movininTypes.Booking description?: boolean className?: string + language: string } const PropertyInfo = ({ @@ -44,6 +45,7 @@ const PropertyInfo = ({ booking, description, className, + language, }: PropertyInfoProps) => { const fr = movininHelper.fr(user) const edit = helper.admin(user) || (user?._id === property.agency._id) @@ -63,7 +65,7 @@ const PropertyInfo = ({ : } - const size = `${property.size} ${env.SIZE_UNIT}` + const size = `${movininHelper.formatNumber(property.size as number, language)} ${env.SIZE_UNIT}` return ( (property && user @@ -159,10 +161,10 @@ const PropertyInfo = ({ ) }
  • - -1 ? strings.CANCELLATION_TOOLTIP : helper.getCancellation(property.cancellation, fr)} placement="left"> + -1 ? strings.CANCELLATION_TOOLTIP : helper.getCancellation(property.cancellation, language)} placement="left">
    {getExtraIcon('cancellation', property.cancellation)} - {helper.getCancellation(property.cancellation, fr)} + {helper.getCancellation(property.cancellation, language)}
  • diff --git a/backend/src/components/PropertyList.tsx b/backend/src/components/PropertyList.tsx index 2701057f..eabe6164 100644 --- a/backend/src/components/PropertyList.tsx +++ b/backend/src/components/PropertyList.tsx @@ -315,6 +315,7 @@ const PropertyList = ({ user={user} booking={booking} className="property-info" + language={language} description />
    @@ -322,7 +323,7 @@ const PropertyList = ({
    {!hidePrice && (
    - {helper.priceLabel(property)} + {helper.priceLabel(property, language)}
    )} diff --git a/backend/src/lang/common.ts b/backend/src/lang/common.ts index 05afc118..287295a0 100644 --- a/backend/src/lang/common.ts +++ b/backend/src/lang/common.ts @@ -30,7 +30,7 @@ const strings = new LocalizedStrings({ SAVE: 'Sauvegarder', CANCEL: 'Annuler', RESET_PASSWORD: 'Changer le mot de passe', - CURRENCY: '€', + CURRENCY: '$', DELETE_AVATAR_CONFIRM: 'Êtes-vous sûr de vouloir supprimer la photo ?', DELETE_IMAGE: "Supprimer l'image", UPLOAD_IMAGE: 'Charger une image', @@ -103,7 +103,7 @@ const strings = new LocalizedStrings({ SAVE: 'Save', CANCEL: 'Cancel', RESET_PASSWORD: 'Change Password', - CURRENCY: '€', + CURRENCY: '$', DELETE_AVATAR_CONFIRM: 'Are you sure you want to delete the picture?', UPLOAD_IMAGE: 'Upload image', DELETE_IMAGE: 'Delete image', diff --git a/backend/src/pages/Property.tsx b/backend/src/pages/Property.tsx index d07e39d4..02166750 100644 --- a/backend/src/pages/Property.tsx +++ b/backend/src/pages/Property.tsx @@ -40,9 +40,10 @@ const Property = () => { const [images, setImages] = useState([]) const [currentIndex, setCurrentIndex] = useState(0) const [openImageDialog, setOpenImageDialog] = useState(false) - const [openDeleteDialog, setOpenDeleteDialog] = useState(false) const [openInfoDialog, setOpenInfoDialog] = useState(false) + const [language, setLanguage] = useState(env.DEFAULT_LANGUAGE) + const edit = helper.admin(user) || (user?._id === property?.agency._id) useEffect(() => { @@ -61,6 +62,7 @@ const Property = () => { if (_user && _user.verified) { setLoading(true) setUser(_user) + setLanguage(_user.language as string) const params = new URLSearchParams(window.location.search) if (params.has('p')) { @@ -136,11 +138,12 @@ const Property = () => {

    {property.name}

    -
    {helper.priceLabel(property)}
    +
    {helper.priceLabel(property, language)}
    diff --git a/backend/src/pages/PropertyBookings.tsx b/backend/src/pages/PropertyBookings.tsx index 0a80af04..9e1b3db5 100644 --- a/backend/src/pages/PropertyBookings.tsx +++ b/backend/src/pages/PropertyBookings.tsx @@ -44,6 +44,7 @@ const PropertyBookings = () => { const [agencies, setAgencies] = useState([]) const [offset, setOffset] = useState(0) const [openInfoDialog, setOpenInfoDialog] = useState(false) + const [language, setLanguage] = useState(env.DEFAULT_LANGUAGE) const statuses = helper.getBookingStatuses().map((status) => status.value) @@ -76,10 +77,12 @@ const PropertyBookings = () => { const onLoad = async (_user?: movininTypes.User) => { setLoading(true) - setUser(_user) const params = new URLSearchParams(window.location.search) if (_user && _user.verified && params.has('p')) { + setUser(_user) + setLanguage(_user?.language as string) + const id = params.get('p') if (id && id !== '') { try { @@ -139,11 +142,12 @@ const PropertyBookings = () => {

    {property.name}

    - {helper.priceLabel(property)} + {helper.priceLabel(property, language)}
    @@ -201,20 +205,20 @@ const PropertyBookings = () => {