Skip to content

Commit

Permalink
fix(price range): default margin 0
Browse files Browse the repository at this point in the history
  • Loading branch information
shadow81627 committed Apr 28, 2022
1 parent cb02cc6 commit 1af3ef7
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 49 deletions.
2 changes: 1 addition & 1 deletion components/price-range.vue
Expand Up @@ -40,7 +40,7 @@ export default {
},
margin: {
type: Number,
default: 0.5,
default: 0,
},
defaultPlan: {
type: Object,
Expand Down
48 changes: 1 addition & 47 deletions pages/tools/index.vue
Expand Up @@ -39,11 +39,10 @@
</template>

<script>
import { sortBy, maxBy, minBy } from 'lodash-es';
import { sortBy, maxBy } from 'lodash-es';
import ImageSources from '@/mixins/srcset';
import Feature from '~/components/feature';
import PriceRange from '~/components/price-range';
import price from '~/utils/price';
import textLength from '~/utils/feature-text-length';
export default {
components: {
Expand Down Expand Up @@ -90,50 +89,5 @@ export default {
],
};
},
methods: {
price,
plans(plans) {
return sortBy(plans ?? this.defaultPlan, 'price');
},
priceMin(plans) {
return minBy(plans, 'price') ?? this.defaultPlan.unset;
},
priceMax(plans) {
return maxBy(plans, 'price') ?? this.defaultPlan.unset;
},
priceSame(plans) {
const min = this.priceMin(plans);
const max = this.priceMax(plans);
return min.price === max.price;
},
priceUnset(plans) {
const min = this.priceMin(plans);
const same = this.priceSame(plans);
return same && min === this.defaultPlan.unset;
},
priceRange(tool) {
const plans = this.plans(tool?.plans);
const max = this.priceMax(plans);
const min = this.priceMin(plans);
const same = this.priceSame(plans);
const unset = this.priceUnset(plans);
return !unset
? `${min.price === 0 ? 'Free' : price(min.price)}${
!same ? ' up to ' : ''
}${!same ? price(max.price) : ''} ${min.currency ?? ''} ${
max.interval ? '/' : ''
} ${max.interval ?? ''}`
: '';
},
totalCost(min = false) {
return this.tools.reduce((acc, tool) => {
const plans = this.plans(tool?.plans);
const price = min
? this.priceMin(plans).price
: this.priceMax(plans).price;
return acc + price;
}, 0);
},
},
};
</script>
2 changes: 1 addition & 1 deletion utils/price.js
Expand Up @@ -2,7 +2,7 @@ export default function price(args) {
const { cost, currency, margin } = {
cost: 0,
currency: 'USD',
margin: 0.5,
margin: 0,
...args,
};
const price = cost / (margin || 1);
Expand Down

1 comment on commit 1af3ef7

@vercel
Copy link

@vercel vercel bot commented on 1af3ef7 Apr 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.