### Clone Sharetribe Example Processes Repository Source: https://github.com/sharetribe/example-processes/blob/master/README.md This command clones the `sharetribe-example-processes` Git repository from GitHub to your local machine. It's the essential first step to obtain the example process definitions. ```bash git clone git@github.com:sharetribe/sharetribe-example-processes.git ``` -------------------------------- ### List Sharetribe Process Details with CLI Source: https://github.com/sharetribe/example-processes/blob/master/README.md This command uses the `flex-cli` to display detailed information about a specific transaction process in your Sharetribe marketplace. It's useful for verifying the status, version, and aliases of a deployed process. ```bash flex-cli process list -m my-marketplace-id --process instant-booking ``` -------------------------------- ### Navigate to Cloned Repository Directory Source: https://github.com/sharetribe/example-processes/blob/master/README.md This command changes the current working directory to the newly cloned `sharetribe-example-processes` directory. This step is crucial before executing any further commands that interact with the repository's contents. ```bash cd sharetribe-example-processes ``` -------------------------------- ### Create Alias for Sharetribe Process Version Source: https://github.com/sharetribe/example-processes/blob/master/README.md This command creates a human-readable alias for a specific version of a Sharetribe transaction process. Aliases simplify referring to and managing different process versions, especially during deployment and updates. ```bash flex-cli process create-alias -m my-marketplace-id --process instant-booking --version 1 --alias release-1 ``` -------------------------------- ### Sharetribe Template for Email Subject Translation Source: https://github.com/sharetribe/example-processes/blob/master/default-purchase/templates/purchase-order-review-by-customer-wanted/purchase-order-review-by-customer-wanted-subject.txt This Sharetribe template snippet illustrates the use of two key helpers: `set-translations` to load a JSON file containing translation strings, and `t` to retrieve and format a translated subject line. The `t` helper takes a translation key, a default string, and optional variables (like `listingTitle`) to be interpolated into the final output. This specific example generates an email subject for a purchase order review. ```Sharetribe Template {{set-translations (asset "content/email-texts.json")}}{{t "PurchaseOrderReviewByCustomerWanted.Subject" "Leave a review for {listingTitle}" listingTitle=transaction.listing.title}} ``` -------------------------------- ### Display Transaction Counter Offer Details Source: https://github.com/sharetribe/example-processes/blob/master/negotiated-booking/templates/counter-offer/counter-offer-subject.txt This snippet demonstrates how to display details of a transaction's counter offer within a template. It uses variables like `other-party.display-name` and `transaction.listing.title`, and invokes the `format-money` inline helper to display the `transaction.payin-total`. ```Handlebars {{other-party.display-name}} made a counter offer for {{transaction.listing.title}} for {{> format-money money=transaction.payin-total}} ``` -------------------------------- ### Define Inline Helper for Money Formatting Source: https://github.com/sharetribe/example-processes/blob/master/negotiated-booking/templates/counter-offer/counter-offer-subject.txt This snippet defines an inline Handlebars helper named 'format-money'. It takes a 'money' object and displays its amount and currency. The `~` characters are used for whitespace control, trimming surrounding whitespace. ```Handlebars {{~#*inline "format-money"~}} {{~money-amount money}} {{money.currency~}} {{~/inline~}} ``` -------------------------------- ### Create New Sharetribe Process with CLI Source: https://github.com/sharetribe/example-processes/blob/master/README.md This command utilizes the `flex-cli` tool to create a new transaction process within your specified Sharetribe marketplace. It requires the marketplace ID, the desired process name (e.g., `instant-booking`), and the local path to the process definition file. ```bash flex-cli process create -m my-marketplace-id --process instant-booking --path instant-booking ``` -------------------------------- ### Sharetribe Email Template Initialization Source: https://github.com/sharetribe/example-processes/blob/master/default-purchase/templates/purchase-order-canceled-to-provider/purchase-order-canceled-to-provider-html.html This snippet demonstrates the initial setup for a Sharetribe email template, including setting translations, locale, and timezone, and establishing a context for transaction data using the 'with' helper. ```Sharetribe Template Language {{set-translations (asset "content/email-texts.json")}} {{set-locale (asset "general/localization.json" "locale" "en_US")}} {{set-timezone transaction.listing.availability-plan.timezone}} {{#with transaction}} ``` -------------------------------- ### Define Instant Booking Microcopy Source: https://github.com/sharetribe/example-processes/blob/master/instant-booking/README.md This snippet provides examples of process-specific microcopy to be added to the application's microcopy file. These strings are used for UI elements related to the instant booking process, such as button labels and page titles. ```javascript "BookingDatesForm.instantBook": "Book", "CheckoutPage.instant-booking.title": "Complete booking", "CheckoutPage.instant-booking.orderBreakdown": "Order breakdown", "InboxPage.instant-booking.booked.status": "Booked", ``` -------------------------------- ### Template Setup and Localization Configuration Source: https://github.com/sharetribe/example-processes/blob/master/default-booking/templates/booking-new-request/booking-new-request-html.html This snippet demonstrates how to configure translations, locale, and timezone settings at the beginning of a Sharetribe template. It ensures that dynamic content is displayed correctly based on user preferences and transaction details. ```Sharetribe Template {{set-translations (asset "content/email-texts.json")}} {{set-locale (asset "general/localization.json" "locale" "en_US")}} {{set-timezone transaction.listing.availability-plan.timezone}} ``` -------------------------------- ### Instant Booking Process Translation Keys Source: https://github.com/sharetribe/example-processes/blob/master/instant-booking/README.md This snippet provides example translation keys and their corresponding values used across different stages and roles within the instant booking process. These keys are typically stored in a microcopy file and are essential for localizing user-facing messages. ```JSON "TransactionPage.ActivityFeed.instant-booking.booked": "The bicycle was booked by {otherUsersName}", "TransactionPage.instant-booking.customer.booked.title": "Your booking was succesful!", "TransactionPage.instant-booking.provider.booked.title": "A booking was made by {customerName}", "TransactionPanel.instant-booking.orderBreakdownTitle": "Order breakdown" ``` -------------------------------- ### Localize Email Subject with Sharetribe Template Source: https://github.com/sharetribe/example-processes/blob/master/default-purchase/templates/purchase-order-received-from-disputed-customer/purchase-order-received-from-disputed-customer-subject.txt This snippet illustrates how to set up translations by loading a JSON asset and then use the `t` (translate) function to retrieve a localized string. It includes a fallback default string and demonstrates passing dynamic variables (like `listingTitle`) to the translation. ```Template {{set-translations (asset "content/email-texts.json")}}{{t "PurchaseOrderReceivedFromDisputedCustomer.Subject" "Your disputed order for {listingTitle} is now considered completed" listingTitle=transaction.listing.title}} ``` -------------------------------- ### Booking Breakdown Summary and Start/End Date Labels Source: https://github.com/sharetribe/example-processes/blob/master/default-booking/templates/booking-accepted-request/booking-accepted-request-html.html This snippet displays the total amount charged to the customer and introduces the booking breakdown section. It includes conditional logic to show 'Start' and 'End' labels, potentially influenced by the presence of a `protected-data.priceVariantName`. ```Sharetribe Template {{t "BookingAcceptedRequest.BookingBreakdown" "Your card has been charged for {amount,number,::.00} {currency}. Here's the booking breakdown." amount=payin-total.amount currency=payin-total.currency}} {{#if protected-data.priceVariantName}} {{protected-data.priceVariantName}} * * * {{t "BookingAcceptedRequest.Start" "Start"}} {{t "BookingAcceptedRequest.End" "End"}} {{else}} {{t "BookingAcceptedRequest.Start" "Start"}} {{t "BookingAcceptedRequest.End" "End"}} {{/if}} ``` -------------------------------- ### Display Transaction Payout Details in Sharetribe Template Source: https://github.com/sharetribe/example-processes/blob/master/instant-booking/templates/booking-money-paid/booking-money-paid-subject.txt This snippet shows how to access and display the total payout amount and its currency for a transaction within a Sharetribe template. It utilizes the `money-amount` helper for formatted currency display and direct property access on the `transaction` object for the currency code. ```Sharetribe Template {{money-amount transaction.payout-total}} {{transaction.payout-total.currency}} ``` -------------------------------- ### Sharetribe Email Subject Translation Template Source: https://github.com/sharetribe/example-processes/blob/master/default-purchase/templates/purchase-order-auto-marked-as-received-customer/purchase-order-auto-marked-as-received-customer-subject.txt This snippet illustrates how to set up translations from a JSON asset and utilize the `t` helper function to construct an email subject line. It demonstrates dynamic content insertion, specifically the listing title, into the translated subject. ```Sharetribe Template {{set-translations (asset "content/email-texts.json")}}{{t "PurchaseOrderAutoMarkedAsReceivedCustomer.Subject" "Your order for {listingTitle} is now considered completed" listingTitle=transaction.listing.title}} ``` -------------------------------- ### Sharetribe Email Subject Line Translation Source: https://github.com/sharetribe/example-processes/blob/master/default-booking/templates/booking-review-by-customer-wanted/booking-review-by-customer-wanted-subject.txt This snippet demonstrates how to set up translations from an asset file and then use the 't' (translate) function to generate a localized email subject line. It specifies a translation key, a default fallback string, and substitutes dynamic variables like 'listingTitle' from the transaction object. ```Sharetribe Template {{set-translations (asset "content/email-texts.json")}}{{t "BookingReviewByCustomerWanted.Subject" "Review your experience with {listingTitle}" listingTitle=transaction.listing.title }} ``` -------------------------------- ### Sharetribe Email Subject Translation Template Source: https://github.com/sharetribe/example-processes/blob/master/default-booking/templates/booking-review-by-other-party-published/booking-review-by-other-party-published-subject.txt This snippet illustrates how to define translations by loading a JSON asset and then applying a translated subject line for an email. It leverages the `set-translations` helper to load translation data and the `t` helper for performing the translation, incorporating dynamic data such as `otherPartyDisplayName`. ```Sharetribe Template {{set-translations (asset "content/email-texts.json")}}{{t "BookingReviewByOtherPartyPublished.Subject" "Review from {otherPartyDisplayName} has been published on your profile" otherPartyDisplayName=other-party.display-name }} ``` -------------------------------- ### Generate Dynamic Email Subject Line with Translations Source: https://github.com/sharetribe/example-processes/blob/master/default-inquiry/templates/inquiry-new-inquiry/inquiry-new-inquiry-subject.txt This snippet demonstrates the use of Sharetribe's templating language to set up translations from a JSON asset and then apply a translation key to generate a dynamic email subject line. It interpolates variables such as `customerDisplayName` and `listingTitle` from a `transaction` object, making the subject line personalized and context-aware. ```Sharetribe Template Language {{set-translations (asset "content/email-texts.json")}}{{t "InquiryNewInquiry.Subject" "{customerDisplayName} has sent you a new inquiry about {listingTitle}" customerDisplayName=transaction.customer.display-name listingTitle=transaction.listing.title }} ``` -------------------------------- ### Translate Email Subject with Dynamic Content Source: https://github.com/sharetribe/example-processes/blob/master/default-purchase/templates/purchase-mark-order-received-reminder/purchase-mark-order-received-reminder-subject.txt This snippet illustrates the process of setting up translations by loading a JSON asset and subsequently using the `t` function to translate an email subject. It includes a default fallback message and demonstrates how to inject dynamic content, such as `listingTitle`, into the translated string. ```Sharetribe Template {{set-translations (asset "content/email-texts.json")}}{{t "PurchaseMarkOrderReceivedReminder.Subject" "Did you receive {listingTitle}? Let us know." listingTitle=transaction.listing.title }} ``` -------------------------------- ### Define and Use Inline Money Formatting Helper in Sharetribe Template Source: https://github.com/sharetribe/example-processes/blob/master/negotiated-booking/templates/new-booking-request-with-offer/new-booking-request-with-offer-subject.txt This snippet defines an inline helper named 'format-money' to display a monetary value and its currency. It then demonstrates how to use this helper within a larger template to present transaction details, specifically a booking request, including the customer's name, listing title, and the formatted total payment. ```Handlebars {{~#*inline "format-money"~}} {{~money-amount money}} {{money.currency~}} {{~/inline~}} {{~transaction.customer.display-name}} has requested to book {{transaction.listing.title}} for {{> format-money money=transaction.payin-total}} ``` -------------------------------- ### Sharetribe Email Subject Translation with Dynamic Content Source: https://github.com/sharetribe/example-processes/blob/master/default-purchase/templates/purchase-order-receipt/purchase-order-receipt-subject.txt This snippet illustrates how to utilize Sharetribe's templating language to set translation files and then translate a subject line for an email. It dynamically inserts the listing title into the translated string, demonstrating both asset loading and dynamic text rendering within the template. ```Sharetribe Template {{set-translations (asset "content/email-texts.json")}}{{t "PurchaseOrderReceipt.Subject" "Thank you for purchasing {listingTitle}" listingTitle=transaction.listing.title}} ``` -------------------------------- ### Sharetribe Email Subject Translation and Templating Source: https://github.com/sharetribe/example-processes/blob/master/default-purchase/templates/purchase-order-canceled-to-provider/purchase-order-canceled-to-provider-subject.txt This snippet demonstrates how to use Sharetribe's templating language to load translation assets and then retrieve a localized email subject. It utilizes the `set-translations` helper to load a JSON file containing translation keys and the `t` helper for translation, dynamically inserting a listing title into the subject line. ```Sharetribe Templating {{set-translations (asset "content/email-texts.json")}}{{t "PurchaseOrderCanceledToProvider.Subject" "An order for {listingTitle} was canceled" listingTitle=transaction.listing.title}} ``` -------------------------------- ### Define Email Subject with Translations and Placeholders Source: https://github.com/sharetribe/example-processes/blob/master/default-purchase/templates/purchase-new-order/purchase-new-order-subject.txt This snippet defines the subject line for a 'Purchase New Order' email. It first uses the `set-translations` helper to load translation assets from 'content/email-texts.json'. Subsequently, the `t` helper is used to retrieve a translated string for 'PurchaseNewOrder.Subject'. Dynamic placeholders like `{customerDisplayName}` and `{transactionListingTitle}` are populated from the `transaction.customer.display-name` and `transaction.listing.title` data, respectively. ```Sharetribe Template {{set-translations (asset "content/email-texts.json")}}{{t "PurchaseNewOrder.Subject" "{customerDisplayName} placed an order for {transactionListingTitle}" listingTitle=transaction.listing.title customerDisplayName=transaction.customer.display-name }} ``` -------------------------------- ### JavaScript: Create Suggested Adjustment Line Item Source: https://github.com/sharetribe/example-processes/blob/master/negotiated-booking/README.md This JavaScript snippet demonstrates how to construct a line item object for the calculated suggested adjustment. It conditionally creates a line item with the code `line-item/suggested-adjustment`, quantity 1, and the `unitPrice` set to the `suggestedAdjustment` amount, making it visible to both customer and provider. This line item is used to reflect the negotiated price difference. ```javascript const suggestedAdjustment = resolveSuggestedAdjustment(order, orderData.negotiatedTotal) const suggestedAdjustmentLineItem = suggestedAdjustment ? [{ code: 'line-item/suggested-adjustment', quantity: 1, unitPrice: suggestedAdjustment, includeFor: ['customer', 'provider'], }] : []; ``` -------------------------------- ### Sharetribe Email Subject Translation with Dynamic Variables Source: https://github.com/sharetribe/example-processes/blob/master/default-purchase/templates/purchase-shipping-time-expired-provider/purchase-shipping-time-expired-provider-subject.txt This snippet illustrates how to set up translations from a JSON asset and then use a translation key (`t`) to retrieve a localized string. It also shows how to pass dynamic variables (like `listingTitle`) to the translation function, which are then interpolated into the translated text. ```Sharetribe Template {{set-translations (asset "content/email-texts.json")}}{{t "PurchaseShippingTimeExpiredProvider.Subject" "An order for {listingTitle} was automatically canceled" listingTitle=transaction.listing.title}} ``` -------------------------------- ### Sharetribe Template for Email Subject Line with Translation Source: https://github.com/sharetribe/example-processes/blob/master/default-purchase/templates/purchase-order-operator-disputed/purchase-order-operator-disputed-subject.txt This snippet illustrates how to construct an email subject line using Sharetribe's templating language. It demonstrates loading translation assets via `set-translations` and using the `t` helper for dynamic translation, incorporating placeholders like `listingTitle` from transaction data. ```Sharetribe Template {{set-translations (asset "content/email-texts.json")}}{{t "PurchaseOrderOperatorDisputed.Subject" "An order for {listingTitle} was disputed" listingTitle=transaction.listing.title}} ``` -------------------------------- ### Sharetribe Email Subject Translation Source: https://github.com/sharetribe/example-processes/blob/master/default-booking/templates/booking-money-paid/booking-money-paid-subject.txt This snippet illustrates the use of Sharetribe's template functions to define translation sources and retrieve translated strings. It shows how to use `set-translations` to load a JSON asset and the `t` function to format a subject line with dynamic values like `amount` and `currency`. ```Sharetribe Template {{set-translations (asset "content/email-texts.json")}}{{t "BookingMoneyPaid.Subject" "You have been paid {amount,number,::.00} {currency}" amount=transaction.payout-total.amount currency=transaction.payout-total.currency}} ``` -------------------------------- ### Sharetribe Email Subject Translation with Dynamic Variables Source: https://github.com/sharetribe/example-processes/blob/master/default-purchase/templates/purchase-order-received-from-disputed-provider/purchase-order-received-from-disputed-provider-subject.txt This snippet illustrates how to use Sharetribe's templating language to define an email subject. It utilizes the `set-translations` helper to load a JSON file containing translation keys and the `t` helper to retrieve a translated string, dynamically inserting the `listingTitle` variable from the transaction object. ```Sharetribe Template {{set-translations (asset "content/email-texts.json")}}{{t "PurchaseOrderReceivedFromDisputedProvider.Subject" "A disputed order for {listingTitle} is now considered completed" listingTitle=transaction.listing.title}} ``` -------------------------------- ### Define Email Subject with Translation and Dynamic Content Source: https://github.com/sharetribe/example-processes/blob/master/default-booking/templates/booking-review-by-provider-wanted/booking-review-by-provider-wanted-subject.txt This snippet uses Sharetribe's templating language to define the subject line for an email. It utilizes the `set-translations` helper to load translation assets from a JSON file and the `t` helper for translation. The `t` helper provides a translation key, a default text, and allows injecting dynamic data like `customerDisplayName` from the `transaction` object into the subject line. ```Sharetribe Template {{set-translations (asset "content/email-texts.json")}}{{t "BookingReviewByProviderWanted.Subject" "Leave a review for {customerDisplayName}" customerDisplayName=transaction.customer.display-name }} ``` -------------------------------- ### Load and Apply Email Translations in Sharetribe Template Source: https://github.com/sharetribe/example-processes/blob/master/default-booking/templates/booking-operator-accepted-request/booking-operator-accepted-request-subject.txt This snippet demonstrates the use of Sharetribe's templating language to first load a JSON translation file using the `set-translations` helper in conjunction with the `asset` helper to reference the file path. Subsequently, it shows how to retrieve a specific translated string for an email subject using the `t` function, providing a fallback default value if the translation key is not found. ```Sharetribe Template {{set-translations (asset "content/email-texts.json")}}{{t "BookingOperatorAcceptedRequest.Subject" "A booking request was accepted on your behalf" }} ``` -------------------------------- ### Sharetribe Template for Localized Email Subject Source: https://github.com/sharetribe/example-processes/blob/master/default-purchase/templates/purchase-review-by-other-party-published/purchase-review-by-other-party-published-subject.txt This snippet illustrates the use of Sharetribe's templating language to construct a localized email subject. It first loads translation data from "content/email-texts.json" using `set-translations` and then applies a translation key `PurchaseReviewByOtherPartyPublished.Subject` with dynamic variables like `otherPartyDisplayName` via the `t` helper. This ensures email subjects are dynamically translated and personalized. ```Sharetribe Templating {{set-translations (asset "content/email-texts.json")}}{{t "PurchaseReviewByOtherPartyPublished.Subject" "Review from {otherPartyDisplayName} has been published on your profile" otherPartyDisplayName=other-party.display-name }} ``` -------------------------------- ### Integrate Instant Booking Process into transaction.js Source: https://github.com/sharetribe/example-processes/blob/master/instant-booking/README.md These snippets illustrate the necessary modifications to `src/transactions/transaction.js` to integrate the new instant booking process. This includes importing the process definition, defining its name, exporting its configuration, and updating the `isBookingProcess` function to recognize the new process. ```javascript import * as instantBookingProcess from './transactionProcessInstantBooking'; ``` ```javascript export const INSTANT_BOOKING_PROCESS_NAME = 'instant-booking'; ``` ```javascript { name: INSTANT_BOOKING_PROCESS_NAME, alias: `${INSTANT_BOOKING_PROCESS_NAME}/release-1`, process: instantBookingProcess, unitTypes: [DAY, NIGHT, HOUR], }, ``` ```javascript export const isBookingProcess = processName => { const latestProcessName = resolveLatestProcessName(processName); const processInfo = PROCESSES.find(process => process.name === latestProcessName); return [BOOKING_PROCESS_NAME, INSTANT_BOOKING_PROCESS_NAME].includes(processInfo?.name); }; ``` -------------------------------- ### Conditionally Display Price Variant Name Source: https://github.com/sharetribe/example-processes/blob/master/default-booking/templates/booking-new-request/booking-new-request-html.html This block checks for the presence of a `priceVariantName` in `protected-data` and displays it if available. It also includes labels for 'Start' and 'End' dates, adapting the display based on whether a specific price variant is defined. ```Sharetribe Template {{#if protected-data.priceVariantName}} {{protected-data.priceVariantName}} * * * {{t "BookingNewRequest.StartLabel" "Start"}} {{t "BookingNewRequest.EndLabel" "End"}} {{else}} {{t "BookingNewRequest.StartLabel" "Start"}} {{t "BookingNewRequest.EndLabel" "End"}} {{/if}} ``` -------------------------------- ### Handlebars Booking Breakdown Table Dates Source: https://github.com/sharetribe/example-processes/blob/master/instant-booking/templates/booking-money-paid/booking-money-paid-html.html This Handlebars snippet generates the date rows for the booking breakdown section, displaying start and end dates/times based on the line item type (hourly, daily, nightly). It uses various date formatting helpers. ```Handlebars Here's the booking breakdown. Start End {{#each tx-line-items}} {{#eq "line-item/hour" code}} {{> format-day-time date=booking.start}} {{> format-day-time date=booking.end}} {{/eq}} {{#eq "line-item/day" code}} {{> format-day date=booking.start}} {{> format-day-before date=booking.end}} {{/eq}} {{#eq "line-item/night" code}} {{> format-day date=booking.start}} {{> format-day date=booking.end}} {{/eq}} {{/each}} {{> format-month-date date=booking.start}} {{> format-month-date date=booking.end}} ``` -------------------------------- ### Configure Instant Booking Listing Type in configListing.js Source: https://github.com/sharetribe/example-processes/blob/master/instant-booking/README.md This snippet defines a new listing type 'instant-booking' in `src/config/configListing.js`, associating it with a specific transaction process and unit type. This configuration is crucial for enabling instant booking functionality within the application. ```javascript { listingType: 'instant-booking', label: 'Instant booking', transactionType: { process: 'instant-booking', alias: 'instant-booking/release-1', unitType: 'day', } } ``` -------------------------------- ### Email Template Initialization and Inline Formatting Helpers Source: https://github.com/sharetribe/example-processes/blob/master/default-booking/templates/booking-accepted-request/booking-accepted-request-html.html This snippet initializes the email template by setting translations, locale, and timezone based on transaction data. It also defines several inline helpers (`format-money`, `format-day`, `format-month-date`, etc.) for consistent formatting of monetary values, dates, and times throughout the email content. ```Sharetribe Template {{set-translations (asset "content/email-texts.json")}} {{set-locale (asset "general/localization.json" "locale" "en_US")}} {{set-timezone transaction.listing.availability-plan.timezone}} {{~#*inline "format-money"}}{{format-text "{amount,number,::.00} {currency}" amount=money.amount currency=money.currency}}{{~/inline~}} {{~#*inline "format-day"}}{{#with transaction.listing.availability-plan}}{{format-text "{date,date,::EE}" date=date}}{{/with}}{{~/inline~}} {{~#*inline "format-day-before"}}{{#with transaction.listing.availability-plan}}{{format-text "{date,date,::EE}" date=(date-transform date days=-1)}}{{/with}}{{~/inline~}} {{~#*inline "format-day-time"}}{{#with transaction.listing.availability-plan}}{{format-text "{date,date,::EEjmm}" date=date}}{{/with}}{{~/inline~}} {{~#*inline "format-month-date"}}{{#with transaction.listing.availability-plan}}{{format-text "{date,date,::MMMd}" date=date}}{{/with}}{{~/inline~}} {{~#*inline "format-month-date-day-before"}}{{#with transaction.listing.availability-plan}}{{format-text "{date,date,::MMMd}" date=(date-transform date days=-1)}}{{/with}}{{~/inline~}} ``` -------------------------------- ### Handlebars Booking Period Display Logic Source: https://github.com/sharetribe/example-processes/blob/master/instant-booking/templates/booking-confirmed-provider/booking-confirmed-provider-html.html Renders the start and end dates/times for a booking, dynamically selecting the appropriate date formatting helper based on the line item type (hourly, daily, or nightly booking). It also displays month and day for the booking period. ```Handlebars {{#each tx-line-items}} {{#eq \"line-item/hour\" code}} {{> format-day-time date=booking.start}} {{> format-day-time date=booking.end}} {{/eq}} {{#eq \"line-item/day\" code}} {{> format-day date=booking.start}} {{> format-day-before date=booking.end}} {{/eq}} {{#eq \"line-item/night\" code}} {{> format-day date=booking.start}} {{> format-day date=booking.end}} {{/eq}} {{/each}} {{> format-month-date date=booking.start}} {{> format-month-date date=booking.end}} ``` -------------------------------- ### Handlebars Helper: Format Date to Month Day Year Source: https://github.com/sharetribe/example-processes/blob/master/instant-booking/templates/booking-confirmed-customer/booking-confirmed-customer-html.html An inline Handlebars partial that formats a date to display only the month, day, and year (e.g., 'MMM d, YYYY'), respecting the specified timezone. This helper is typically used for displaying booking start or end dates. ```Handlebars {{#*inline "format-date-day"}} {{#with transaction.listing.availability-plan}} {{date date format="MMM d, YYYY" tz=timezone}} {{/with}} {{/inline}} ``` -------------------------------- ### Update InboxPage State Data for Instant Booking Source: https://github.com/sharetribe/example-processes/blob/master/instant-booking/README.md These snippets demonstrate the necessary changes to `src/containers/InboxPage/InboxPage.stateData.js` to integrate the instant booking process. This includes importing the process name and its associated state data function, and adding a conditional statement to return the correct state data for instant booking transactions. ```javascript import { BOOKING_PROCESS_NAME, INSTANT_BOOKING_PROCESS_NAME, PRODUCT_PROCESS_NAME, resolveLatestProcessName, getProcess, } from '../../transactions/transaction'; ``` ```javascript import { getStateDataForInstantBookingProcess } from './InboxPage.stateDataInstantBooking.js'; ``` ```javascript else if (processName === INSTANT_BOOKING_PROCESS_NAME) { return getStateDataForInstantBookingProcess(params, processInfo()); } ``` -------------------------------- ### Sharetribe Email Subject Localization Source: https://github.com/sharetribe/example-processes/blob/master/default-purchase/templates/purchase-order-operator-marked-as-delivered/purchase-order-operator-marked-as-delivered-subject.txt This snippet illustrates how to define and use translated email subjects within a Sharetribe template. It utilizes the `set-translations` helper to load translation assets and the `t` helper for dynamic translation, interpolating variables like `listingTitle` and `option` based on transaction data. ```Sharetribe Template {{set-translations (asset "content/email-texts.json")}}{{t "PurchaseOrderOperatorMarkedAsDelivered.Subject" "An order for {listingTitle} was marked as {option, select, shipping {shipped} other {delivered}} on your behalf" option=transaction.protected-data.deliveryMethod listingTitle=transaction.listing.title}} ``` -------------------------------- ### Update TransactionPage State Data for Instant Booking Source: https://github.com/sharetribe/example-processes/blob/master/instant-booking/README.md These snippets show how to modify `src/containers/TransactionPage/TransactionPage.stateData.js` to correctly handle the state data for the instant booking process. This involves importing the new process name and its state data function, and adding a conditional block to return the appropriate state information. ```javascript import { BOOKING_PROCESS_NAME, PRODUCT_PROCESS_NAME, INSTANT_BOOKING_PROCESS_NAME, resolveLatestProcessName, } from '../../transactions/transaction'; ``` ```javascript import { getStateDataForInstantBookingProcess } from './TransactionPage.stateDataInstantBooking.js'; ``` ```javascript else if (processName === INSTANT_BOOKING_PROCESS_NAME) { return getStateDataForInstantBookingProcess(params, processInfo()); } ``` -------------------------------- ### Define Inline Helpers for Date and Money Formatting Source: https://github.com/sharetribe/example-processes/blob/master/default-booking/templates/booking-new-request/booking-new-request-html.html This section defines several inline Handlebars-like helpers for consistent formatting of money and various date representations (day, day-time, month-date). These helpers abstract complex formatting logic, making the main template cleaner and more readable. ```Sharetribe Template {{~#*inline "format-money"~}}{{format-text "{amount,number,::.00} {currency}" amount=money.amount currency=money.currency}}{{~/inline~}} {{~#*inline "format-day"~}}{{#with transaction.listing.availability-plan}}{{format-text "{date,date,::EE}" date=date}}{{/with}}{{~/inline~}} {{~#*inline "format-day-before"~}}{{#with transaction.listing.availability-plan}}{{format-text "{date,date,::EE}" date=(date-transform date days=-1)}}{{/with}}{{~/inline~}} {{~#*inline "format-day-time"~}}{{#with transaction.listing.availability-plan}}{{format-text "{date,date,::EEjmm}" date=date}}{{/with}}{{~/inline~}} {{~#*inline "format-month-date"~}}{{#with transaction.listing.availability-plan}}{{format-text "{date,date,::MMMd}" date=date}}{{/with}}{{~/inline~}} {{~#*inline "format-month-date-day-before"~}}{{#with transaction.listing.availability-plan}}{{format-text "{date,date,::MMMd}" date=(date-transform date days=-1)}}{{/with}}{{~/inline~}} ``` -------------------------------- ### Passing transactionProcessAlias to BookingDatesForm Source: https://github.com/sharetribe/example-processes/blob/master/instant-booking/README.md This code demonstrates how to pass the `transactionProcessAlias` as a prop to the `BookingDatesForm` component. This prop is crucial for enabling the component to conditionally render different translations or UI elements based on the specific transaction process in use, such as instant booking. ```JavaScript transactionProcessAlias={transactionProcessAlias} ``` -------------------------------- ### JavaScript: Calculate Suggested Price Adjustment Source: https://github.com/sharetribe/example-processes/blob/master/negotiated-booking/README.md This JavaScript function, `resolveSuggestedAdjustment`, calculates the monetary difference between an order's original total and a negotiated total. It returns a `Money` object representing the adjustment, which is negative if it's a discount or positive if it's an additional charge. It returns `null` if no negotiated total is provided. ```javascript // Returns the adjustment as negative if it is a discount, and // positive if it is an extra payment. exports.resolveSuggestedAdjustment = (order, negotiatedTotal) => { if (!negotiatedTotal) { return null; } const orderTotalAmount = order.unitPrice.amount * order.quantity; return new Money(negotiatedTotal.amount - orderTotalAmount, negotiatedTotal.currency); } ``` -------------------------------- ### Handlebars Booking Acceptance Email - Initial Details Source: https://github.com/sharetribe/example-processes/blob/master/negotiated-booking/templates/provider-accepted-offer/provider-accepted-offer-html.html This section of the Handlebars template displays the initial booking acceptance message, dynamically adjusting the text based on the type of booking (hourly, daily, or nightly). It uses previously defined date formatting partials to show the start and end times/dates of the booking. ```Handlebars {{#with transaction}} Your booking request was accepted ================================= {{#each tx-line-items}}{{#eq "line-item/hour" code}} {{ provider.display-name }} has accepted your booking request for {{ listing.title }} from {{> format-date date=booking.start}} to {{> format-date date=booking.end}}. {{/eq}}{{#eq "line-item/day" code}} {{ provider.display-name }} has accepted your booking request for {{ listing.title }} from {{> format-date- ay date=booking.start}} to {{> format-date-day-before date=booking.end}}. {{/eq}}{{#eq "line-item/night" code}} {{ provider.display-name }} has accepted your booking request for {{ listing.title }} from {{> format-date-day date=booking.start}} to {{> format-date-day date=booking.end}}. {{/eq}}{{/each}} Next, you need to complete the payment for {{> format-money money=payin-total}}. Here's the booking breakdown. ``` -------------------------------- ### Sharetribe Email Subject Line Translation with Dynamic Variables Source: https://github.com/sharetribe/example-processes/blob/master/default-purchase/templates/purchase-order-disputed/purchase-order-disputed-subject.txt This snippet demonstrates how to use Sharetribe's templating language to define a translatable email subject line. It utilizes the `t` helper for translation, referencing a translation key (`PurchaseOrderDisputed.Subject`) and providing default text. Dynamic variables such as `customerDisplayName` and `listingTitle` are passed as arguments to be interpolated into the subject line, enhancing personalization. It also includes a `set-translations` helper to load translation assets. ```Sharetribe Template {{set-translations (asset "content/email-texts.json")}}{{t "PurchaseOrderDisputed.Subject" "{customerDisplayName} disputed an order for {listingTitle}" customerDisplayName=transaction.customer.display-name listingTitle=transaction.listing.title}} ``` -------------------------------- ### Sharetribe Email Subject Line Translation Source: https://github.com/sharetribe/example-processes/blob/master/default-purchase/templates/purchase-shipping-time-expired-customer/purchase-shipping-time-expired-customer-subject.txt This snippet illustrates how to load translation strings from a JSON asset ('content/email-texts.json') using 'set-translations' and then use the 't' helper function to translate an email subject. It also shows how to provide a fallback string and dynamically insert variables like 'listingTitle' from the transaction context into the translated string. ```Sharetribe Template {{set-translations (asset "content/email-texts.json")}}{{t "PurchaseShippingTimeExpiredCustomer.Subject" "Your order for {listingTitle} was automatically canceled" listingTitle=transaction.listing.title}} ```