Skip to content

Commit

Permalink
Merge pull request #120 from Holo-Host/feature/happ-paid-free-option
Browse files Browse the repository at this point in the history
feat(hosting-plan): implement radio buttons and modals
  • Loading branch information
mateuszRybczonek authored Nov 22, 2023
2 parents bb0a31a + 0fb994e commit d09df88
Show file tree
Hide file tree
Showing 9 changed files with 524 additions and 30 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "host-console",
"version": "1.0.0-alpha.9",
"version": "1.0.0-alpha.10",
"private": true,
"homepage": "https://holo-host.github.io/host-console-ui/",
"scripts": {
Expand Down
132 changes: 132 additions & 0 deletions src/components/BaseRadioButton.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<script lang="ts" setup>
import { ref } from 'vue'
const props = defineProps<{
id: string
value: string
label: string
description: string
modelValue: string
}>()
const emit = defineEmits(['update:modelValue'])
const localValue = ref(props.modelValue)
</script>

<template>
<div class="base-radio-button__wrapper">
<label
class="base-radio-button__button"
for="html"
data-ripple-dark="true"
>
<input
:id="props.id"
v-model="localValue"
name="type"
type="radio"
:value="props.value"
class="base-radio-button__input"
@change="emit('update:modelValue', props.value)"
/>
<div class="base-radio-button__input-inner">
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 16 16"
fill="currentColor"
>
<circle
data-name="ellipse"
cx="8"
cy="8"
r="8"
></circle>
</svg>
</div>
</label>

<div class="base-radio-button__labels">
<label
class="base-radio-button__label"
:for="props.id"
>
{{ props.label }}
</label>

<label
class="base-radio-button__description"
:for="props.id"
>
{{ props.description }}
</label>
</div>
</div>
</template>

<style lang="scss" scoped>
.base-radio-button {
&__wrapper {
display: inline-flex;
align-items: start;
}
&__button {
position: relative;
display: flex;
align-items: center;
cursor: pointer;
border-radius: 9999px;
padding: 0;
margin-top: 2px;
}
&__input {
position: relative;
height: 15px;
width: 15px;
cursor: pointer;
appearance: none;
border-radius: 9999px;
border: 1px solid var(--grey-dark-color);
&:checked {
border-color: var(--primary-color);
background-color: rgba(0, 202, 217, 0.15);
& + .base-radio-button__input-inner {
opacity: 1;
}
}
&-inner {
position: absolute;
pointer-events: none;
left: 3px;
top: -2px;
color: var(--primary-color);
opacity: 0;
height: 9px;
width: 9px;
}
}
&__labels {
display: flex;
flex-direction: column;
margin-left: 8px;
}
&__label {
font-weight: 800;
cursor: pointer;
}
&__description {
font-weight: 600;
font-size: 12px;
color: var(--grey-light-color);
cursor: pointer;
}
}
</style>
4 changes: 2 additions & 2 deletions src/components/PrimaryLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ onMounted(async () => {
isLoading.value = false
}
await nextTick(() => {
if (!userStore.holoFuel.nickname) {
await nextTick(() => {
if (!userStore.holoFuel.nickname) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
showModal(EModal.welcome)
}
Expand Down
18 changes: 17 additions & 1 deletion src/components/hAppDetails/HAppDetailsContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import HAppImage from '@uicommon/components/HAppImage.vue'
import { useI18n } from 'vue-i18n'
import CategoryChip from '@/components/CategoryChip.vue'
import HAppDetailsEarnings from '@/components/hAppDetails/HAppDetailsEarnings.vue'
import HAppDetailsHostingPlan from '@/components/hAppDetails/HAppDetailsHostingPlan.vue'
import HAppDetailsStopHosting from '@/components/hAppDetails/HAppDetailsStopHosting.vue'
import HAppDetailsUsage from '@/components/hAppDetails/HAppDetailsUsage.vue'
import LeftChevronIcon from '@/components/icons/LeftChevronIcon.vue'
Expand All @@ -14,11 +15,15 @@ const props = defineProps<{
hApp: HAppDetails
}>()
const emit = defineEmits(['update:hosting'])
const emit = defineEmits(['update:hosting', 'update:hosting-plan'])
function updateHosting(isEnabled: boolean): void {
emit('update:hosting', isEnabled)
}
function updateHostingPlan(plan: 'free' | 'paid'): void {
emit('update:hosting-plan', plan)
}
</script>

<template>
Expand Down Expand Up @@ -96,6 +101,13 @@ function updateHosting(isEnabled: boolean): void {
:h-app="props.hApp"
class="happ-details__main-column-usage"
/>

<HAppDetailsHostingPlan
v-if="props.hApp.enabled"
:h-app="props.hApp"
class="happ-details__main-column-hosting-plan"
@update:hosting-plan="updateHostingPlan"
/>
</div>
</div>
</div>
Expand Down Expand Up @@ -193,6 +205,10 @@ function updateHosting(isEnabled: boolean): void {
&-usage {
margin-top: 32px;
}
&-hosting-plan {
margin-top: 54px;
}
}
}
Expand Down
101 changes: 101 additions & 0 deletions src/components/hAppDetails/HAppDetailsHostingPlan.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<script setup lang="ts">
import { ref } from 'vue'
import { useI18n } from 'vue-i18n'
import BaseRadioButton from '@/components/BaseRadioButton.vue'
import HostingPlanModal from '@/components/modals/HostingPlanModal.vue'
import type { HAppDetails } from '@/interfaces/HposInterface'
const { t } = useI18n()
const props = defineProps<{
hApp: HAppDetails
}>()
const emit = defineEmits(['update:hosting-plan'])
const planValue = ref<'free' | 'paid'>(props.hApp.hostingPlan)
const isModalVisible = ref(false)
function openModal(): void {
isModalVisible.value = true
}
function closeModal(): void {
isModalVisible.value = false
}
function showConfirmation(value: 'free' | 'paid'): void {
planValue.value = value
openModal()
}
function updatePlan(value: 'free' | 'paid'): void {
planValue.value = value
emit('update:hosting-plan', value)
}
</script>

<template>
<div class="happ-details-hosting-plan">
<span class="happ-details-hosting-plan__title">{{ t('happ_details.hosting_plan.label') }}</span>
<div class="happ-details-hosting-plan__radio-buttons">
<BaseRadioButton
id="happ-details-hosting-plan-paid"
:key="planValue"
value="paid"
:model-value="planValue"
:label="t('happ_details.hosting_plan.paid')"
:description="t('happ_details.hosting_plan.paid_description')"
class="happ-details-hosting-plan__radio-button-paid"
@update:model-value="showConfirmation"
/>

<BaseRadioButton
id="happ-details-hosting-plan-free"
:key="planValue"
value="free"
:model-value="planValue"
:label="t('happ_details.hosting_plan.free')"
:description="t('happ_details.hosting_plan.free_description')"
class="happ-details-hosting-plan__radio-button-free"
@update:model-value="showConfirmation"
/>
</div>

<HostingPlanModal
v-if="props.hApp"
:h-app="props.hApp"
:plan-value="planValue"
:is-visible="isModalVisible"
@close="closeModal"
@update:hosting-plan="updatePlan"
/>
</div>
</template>

<style scoped lang="scss">
.happ-details-hosting-plan {
display: flex;
flex-direction: column;
&__title {
font-size: 16px;
font-weight: 800;
}
&__radio-buttons {
display: flex;
flex-direction: column;
margin-top: 18px;
}
&__radio-button-free {
margin-top: 12px;
}
}
@media screen and (max-width: 1050px) {
.happ-details-hosting-plan {
}
}
</style>
Loading

0 comments on commit d09df88

Please sign in to comment.