Skip to content

Commit

Permalink
Update currency and price formats
Browse files Browse the repository at this point in the history
  • Loading branch information
aelassas committed Apr 16, 2024
1 parent 28b0834 commit 75a78cd
Show file tree
Hide file tree
Showing 26 changed files with 170 additions and 99 deletions.
21 changes: 13 additions & 8 deletions backend/src/common/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`
}

/**
Expand Down Expand Up @@ -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)}`
6 changes: 3 additions & 3 deletions backend/src/components/BookingList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ const BookingList = ({
headerName: strings.PRICE,
flex: 1,
renderCell: ({ value }: GridRenderCellParams<movininTypes.Booking, string>) => <span className="bp">{value}</span>,
valueGetter: (value: number) => `${movininHelper.formatNumber(value)} ${commonStrings.CURRENCY}`,
valueGetter: (value: number) => movininHelper.formatPrice(value, commonStrings.CURRENCY, language as string),
},
{
field: 'status',
Expand Down Expand Up @@ -550,7 +550,7 @@ const BookingList = ({
<div className="extra">
<CheckIcon className="extra-icon" />
<span className="extra-title">{csStrings.CANCELLATION}</span>
<span className="extra-text">{helper.getCancellationOption((booking.property as movininTypes.Property).cancellation, _fr, true)}</span>
<span className="extra-text">{helper.getCancellationOption((booking.property as movininTypes.Property).cancellation, language as string, true)}</span>
</div>
)}

Expand All @@ -560,7 +560,7 @@ const BookingList = ({

<div className="booking-detail" style={{ height: bookingDetailHeight }}>
<span className="booking-detail-title">{strings.COST}</span>
<div className="booking-detail-value booking-price">{`${movininHelper.formatNumber(booking.price)} ${commonStrings.CURRENCY}`}</div>
<div className="booking-detail-value booking-price">{movininHelper.formatPrice(booking.price as number, commonStrings.CURRENCY, language as string)}</div>
</div>

<div className="bs-buttons">
Expand Down
8 changes: 5 additions & 3 deletions backend/src/components/PropertyInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ interface PropertyInfoProps {
booking?: movininTypes.Booking
description?: boolean
className?: string
language: string
}

const PropertyInfo = ({
Expand All @@ -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)
Expand All @@ -63,7 +65,7 @@ const PropertyInfo = ({
: <InfoIcon className="extra-info" />
}

const size = `${property.size} ${env.SIZE_UNIT}`
const size = `${movininHelper.formatNumber(property.size as number, language)} ${env.SIZE_UNIT}`

return (
(property && user
Expand Down Expand Up @@ -159,10 +161,10 @@ const PropertyInfo = ({
)
}
<li>
<Tooltip title={booking ? '' : property.cancellation > -1 ? strings.CANCELLATION_TOOLTIP : helper.getCancellation(property.cancellation, fr)} placement="left">
<Tooltip title={booking ? '' : property.cancellation > -1 ? strings.CANCELLATION_TOOLTIP : helper.getCancellation(property.cancellation, language)} placement="left">
<div className="property-info-list-item">
{getExtraIcon('cancellation', property.cancellation)}
<span className="property-info-list-text">{helper.getCancellation(property.cancellation, fr)}</span>
<span className="property-info-list-text">{helper.getCancellation(property.cancellation, language)}</span>
</div>
</Tooltip>
</li>
Expand Down
3 changes: 2 additions & 1 deletion backend/src/components/PropertyList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -315,14 +315,15 @@ const PropertyList = ({
user={user}
booking={booking}
className="property-info"
language={language}
description
/>
</div>

<div className="right-panel">
{!hidePrice && (
<div className="price">
{helper.priceLabel(property)}
{helper.priceLabel(property, language)}
</div>
)}

Expand Down
4 changes: 2 additions & 2 deletions backend/src/lang/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
7 changes: 5 additions & 2 deletions backend/src/pages/Property.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ const Property = () => {
const [images, setImages] = useState<string[]>([])
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(() => {
Expand All @@ -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')) {
Expand Down Expand Up @@ -136,11 +138,12 @@ const Property = () => {
<div className="right-panel">
<div className="right-panel-header">
<div className="name"><h2>{property.name}</h2></div>
<div className="price">{helper.priceLabel(property)}</div>
<div className="price">{helper.priceLabel(property, language)}</div>
</div>
<PropertyInfo
property={property}
user={user}
language={language}
/>
</div>
</div>
Expand Down
34 changes: 19 additions & 15 deletions backend/src/pages/PropertyBookings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const PropertyBookings = () => {
const [agencies, setAgencies] = useState<string[]>([])
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)

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -139,11 +142,12 @@ const PropertyBookings = () => {
</div>
<div className="name"><h2>{property.name}</h2></div>
<div className="price">
{helper.priceLabel(property)}
{helper.priceLabel(property, language)}
</div>
<PropertyInfo
property={property}
user={user}
language={language}
description
/>
</section>
Expand Down Expand Up @@ -201,20 +205,20 @@ const PropertyBookings = () => {
</Button>
<Button
onClick={async () => {
try {
setOpenDeleteDialog(false)

const status = await PropertyService.deleteProperty(property._id)

if (status === 200) {
navigate('/properties')
} else {
helper.error()
try {
setOpenDeleteDialog(false)

const status = await PropertyService.deleteProperty(property._id)

if (status === 200) {
navigate('/properties')
} else {
helper.error()
}
} catch (err) {
helper.error(err)
}
} catch (err) {
helper.error(err)
}
}}
}}
variant="contained"
color="error"
>
Expand Down
8 changes: 5 additions & 3 deletions backend/src/pages/UpdateBooking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const UpdateBooking = () => {
const [status, setStatus] = useState<movininTypes.BookingStatus>()
const [cancellation, setCancellation] = useState(false)
const [openDeleteDialog, setOpenDeleteDialog] = useState(false)
const [language, setLanguage] = useState(env.DEFAULT_LANGUAGE)

const handleAgencyChange = (values: movininTypes.Option[]) => {
setAgency(values.length > 0 ? values[0] : undefined)
Expand Down Expand Up @@ -209,8 +210,9 @@ const UpdateBooking = () => {

const onLoad = async (_user?: movininTypes.User) => {
if (_user) {
setUser(_user)
setLoading(true)
setUser(_user)
setLanguage(_user.language as string)

const params = new URLSearchParams(window.location.search)
if (params.has('b')) {
Expand Down Expand Up @@ -437,8 +439,8 @@ const UpdateBooking = () => {
<div className="col-2-header">
<div className="price">
<span className="price-days">{helper.getDays(days)}</span>
<span className="price-main">{`${movininHelper.formatNumber(price ?? 0)} ${commonStrings.CURRENCY}`}</span>
<span className="price-day">{`${csStrings.PRICE_PER_DAY} ${Math.floor((price ?? 0) / days)} ${commonStrings.CURRENCY}`}</span>
<span className="price-main">{`${movininHelper.formatPrice(price as number, commonStrings.CURRENCY, language)}`}</span>
<span className="price-day">{`${csStrings.PRICE_PER_DAY} ${movininHelper.formatPrice(Math.floor((price as number) / days), commonStrings.CURRENCY, language)}`}</span>
</div>
</div>
<PropertyList
Expand Down
21 changes: 13 additions & 8 deletions frontend/src/common/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,33 +235,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)}`
}

/**
Expand Down Expand Up @@ -358,7 +362,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)}`
6 changes: 3 additions & 3 deletions frontend/src/components/BookingList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ const BookingList = ({
headerName: strings.PRICE,
flex: 1,
renderCell: ({ value }: GridRenderCellParams<movininTypes.Booking, string>) => <span className="bp">{value}</span>,
valueGetter: (value: number) => `${movininHelper.formatNumber(value)} ${commonStrings.CURRENCY}`,
valueGetter: (value: number) => movininHelper.formatPrice(value, commonStrings.CURRENCY, language as string),
},
{
field: 'status',
Expand Down Expand Up @@ -459,7 +459,7 @@ const BookingList = ({
<div className="extra">
<CheckIcon className="extra-icon" />
<span className="extra-title">{csStrings.CANCELLATION}</span>
<span className="extra-text">{helper.getCancellationOption((booking.property as movininTypes.Property).cancellation, _fr, true)}</span>
<span className="extra-text">{helper.getCancellationOption((booking.property as movininTypes.Property).cancellation, language as string, true)}</span>
</div>
)}

Expand All @@ -469,7 +469,7 @@ const BookingList = ({

<div className="booking-detail" style={{ height: bookingDetailHeight }}>
<span className="booking-detail-title">{strings.COST}</span>
<div className="booking-detail-value booking-price">{`${movininHelper.formatNumber(booking.price)} ${commonStrings.CURRENCY}`}</div>
<div className="booking-detail-value booking-price">{movininHelper.formatPrice(booking.price as number, commonStrings.CURRENCY, language as string)}</div>
</div>

<div className="bs-buttons">
Expand Down
Loading

0 comments on commit 75a78cd

Please sign in to comment.