Skip to content
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

Einstiegsangebot-Test #835

Merged
merged 7 commits into from
May 23, 2024
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
37 changes: 26 additions & 11 deletions apps/www/components/Pledge/CustomizePackage.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ const dayFormat = timeFormat('%d. %B %Y')
const { P } = Interaction

const absolutMinPrice = 100
const calculateMinPrice = (pkg, values, userPrice) => {
const calculateMinPrice = (pkg, values, userPrice, router) => {
// EINSTIEGSMONAT-TEST (remove after test)
if (pkg.name === 'MONTHLY_ABO' && router.query.coupon === 'EINSTIEG24') {
return 200
}
const minPrice = pkg.options.reduce((price, option) => {
const amountValue = values[getOptionFieldKey(option)]
const amount =
Expand Down Expand Up @@ -79,14 +83,18 @@ const calculateMinPrice = (pkg, values, userPrice) => {
return absolutMinPrice
}

const getPrice = ({ values, pkg, userPrice }) => {
const getPrice = ({ values, pkg, userPrice, router }) => {
// EINSTIEGSMONAT-TEST (remove after test)
if (pkg.name === 'MONTHLY_ABO' && router.query.coupon === 'EINSTIEG24') {
return 200
}
if (values.price !== undefined) {
return values.price
} else {
if (userPrice) {
return ''
}
const minPrice = calculateMinPrice(pkg, values, userPrice)
const minPrice = calculateMinPrice(pkg, values, userPrice, router)
if (minPrice === absolutMinPrice) {
return ''
}
Expand Down Expand Up @@ -195,7 +203,7 @@ class CustomizePackage extends Component {
}
}
calculateNextPrice(nextFields) {
const { pkg, values, userPrice, t } = this.props
const { pkg, values, userPrice, t, router } = this.props

const minPrice = calculateMinPrice(
pkg,
Expand All @@ -204,6 +212,7 @@ class CustomizePackage extends Component {
...nextFields.values,
},
userPrice,
router
)

let price = values.price
Expand All @@ -230,7 +239,7 @@ class CustomizePackage extends Component {
if (values.price === undefined && pkg.suggestedTotal) {
if (process.browser) {
this.setState({ customPrice: true })
const regularMinPrice = calculateMinPrice(pkg, values, false)
const regularMinPrice = calculateMinPrice(pkg, values, false, router)
if (pkg.suggestedTotal < regularMinPrice && !userPrice) {
router.replace(
{
Expand Down Expand Up @@ -258,10 +267,10 @@ class CustomizePackage extends Component {
}
}

const { onChange, pkg, values, userPrice, fixedPrice, t } = this.props
const { onChange, pkg, values, userPrice, fixedPrice, t, router } = this.props

const price = this.getPriceWithSuggestion()
const minPrice = calculateMinPrice(pkg, values, userPrice)
const minPrice = calculateMinPrice(pkg, values, userPrice, router)
onChange({
values: {
price,
Expand All @@ -273,11 +282,11 @@ class CustomizePackage extends Component {
})
}
componentDidUpdate(prevProps) {
const { onChange, pkg, values, userPrice, t } = this.props
const { onChange, pkg, values, userPrice, t, router } = this.props

if (values.price === undefined || userPrice !== prevProps.userPrice) {
const price = this.getPriceWithSuggestion()
const minPrice = calculateMinPrice(pkg, values, userPrice)
const minPrice = calculateMinPrice(pkg, values, userPrice, router)
onChange({
values: {
price,
Expand Down Expand Up @@ -360,8 +369,8 @@ class CustomizePackage extends Component {
return fields
}, [])

const minPrice = calculateMinPrice(pkg, values, userPrice)
const regularMinPrice = calculateMinPrice(pkg, values, false)
const minPrice = calculateMinPrice(pkg, values, userPrice, router)
const regularMinPrice = calculateMinPrice(pkg, values, false, router)

const onPriceChange = (_, value, shouldValidate) => {
const price = String(value).length
Expand Down Expand Up @@ -514,6 +523,9 @@ class CustomizePackage extends Component {
`package/${crowdfundingName}/${pkg.name}/${ownMembership.type.name}/description`,
ownMembership &&
`package/${pkg.name}/${ownMembership.type.name}/description`,
// EINSTIEGSMONAT-TEST (remove after test)
router.query.coupon === 'EINSTIEG24' &&
`package/${pkg.name}/einstiegsmonat/description`,
`package/${crowdfundingName}/${pkg.name}/description`,
`package/${pkg.name}/description`,
].filter(Boolean)
Expand All @@ -530,6 +542,9 @@ class CustomizePackage extends Component {
ownMembership &&
new Date(ownMembership.graceEndDate) < new Date() &&
`package/${pkg.name}/reactivate/pageTitle`,
// EINSTIEGSMONAT-TEST (remove after test)
router.query.coupon === 'EINSTIEG24' &&
`package/${pkg.name}/einstiegsmonat/title`,
`package/${pkg.name}/pageTitle`,
`package/${pkg.name}/title`,
].filter(Boolean),
Expand Down
7 changes: 6 additions & 1 deletion apps/www/components/Pledge/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,14 @@ class Pledge extends Component {
? !['YEARLY_ABO', 'MONTHLY_ABO', 'DONATE', 'LESHA'].includes(pkg.name)
: undefined,
paymentMethods: pkg ? pkg.paymentMethods : undefined,
total: values.price || undefined,
// EINSTIEGSMONAT-TEST (remove after test) change total back
total:
pkg.name === 'MONTHLY_ABO' && query.coupon === 'EINSTIEG24'
? values.price + 2000
: values.price || undefined,
options,
reason: userPrice ? values.reason : undefined,
coupon: query.coupon,
id: pledge ? pledge.id : undefined,
pledgeShippingAddress: pledge ? pledge.shippingAddress : undefined,
pledgeUser: pledge ? pledge.user : undefined,
Expand Down
11 changes: 8 additions & 3 deletions apps/www/components/Pledge/Submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1074,9 +1074,13 @@ class Submit extends Component {
}}
>
{t('pledge/submit/button/pay', {
formattedChf: this.props.total
? chfFormat(this.props.total / 100)
: '',
formattedChf:
// EINSTIEGSMONAT-TEST (remove after test)
this.props.coupon === 'EINSTIEG24'
? chfFormat(2)
: this.props.total
? chfFormat(this.props.total / 100)
: '',
})}
</Button>
</div>
Expand All @@ -1093,6 +1097,7 @@ Submit.propTypes = {
paymentMethods: PropTypes.array,
total: PropTypes.number,
reason: PropTypes.string,
coupon: PropTypes.string,
options: PropTypes.array.isRequired,
submit: PropTypes.func.isRequired,
errors: PropTypes.object.isRequired,
Expand Down
8 changes: 8 additions & 0 deletions apps/www/lib/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -2572,6 +2572,10 @@
"key": "package/MONTHLY_ABO/title",
"value": "Monats-Abo"
},
{
"key": "package/MONTHLY_ABO/einstiegsmonat/title",
"value": "Monats-Abo zum Einstiegspreis"
},
{
"key": "package/MONTHLY_ABO/price",
"value": "{formattedCHF}"
Expand All @@ -2580,6 +2584,10 @@
"key": "package/MONTHLY_ABO/description",
"value": "Schön, dass Sie dabei sind. Sie erhalten ab sofort unser Magazin. Und sind während der Zeit Ihres Abonnements Verlegerin oder Verleger der Republik. Das Monatsabonnement wird jeweils automatisch verlängert. Sie können es aber jederzeit in Ihrem Konto kündigen."
},
{
"key": "package/MONTHLY_ABO/einstiegsmonat/description",
"value": "Das Abo erneuert nach 30 Tagen automatisch zum regulären Preis von CHF 22.-. Es ist jederzeit kündbar."
},
{
"key": "package/LESHA/title",
"value": "Buch «We Stay»"
Expand Down
13 changes: 13 additions & 0 deletions apps/www/lib/utils/track.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ export const getCampaignReferralParams = (query) => {
return params
}

export const getCouponCodeParams = (query) => {
let params = {}
Object.keys(query)
.filter((key) => key.startsWith('coupon'))
.sort((a, b) => ascending(a, b))
.forEach((key) => {
params[key] = query[key]
})

return params
}

const createPayloadStore = (storeKey, limit = 15) => {
let payload = {}
let isEnabled = true
Expand Down Expand Up @@ -111,5 +123,6 @@ export const getConversionPayload = (query = {}) => {
...payload.get(),
...getUtmParams(query),
...getCampaignReferralParams(query),
...getCouponCodeParams(query),
}
}
Loading