Skip to content

Commit

Permalink
feat: Improve account details page
Browse files Browse the repository at this point in the history
  • Loading branch information
letehaha committed Jan 25, 2024
1 parent 0f81aba commit e789e59
Show file tree
Hide file tree
Showing 6 changed files with 231 additions and 263 deletions.
95 changes: 95 additions & 0 deletions src/pages/account/components/account-details-tab.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@

<script setup lang="ts">
import { ref } from "vue";
import { storeToRefs } from "pinia";
import { AccountModel } from "shared-types";
import { ChevronDownIcon, ChevronUpIcon } from "lucide-vue-next";
import * as Tabs from "@/components/lib/ui/tabs";
import * as Collapsible from "@/components/lib/ui/collapsible";
import { Separator } from "@/components/lib/ui/separator";
import { useCurrenciesStore } from "@/stores";
import { toLocalNumber } from "@/js/helpers";
defineProps<{
account: AccountModel;
tabName: string;
}>();
const { currenciesMap } = storeToRefs(useCurrenciesStore());
const isOpen = ref(false);
</script>

<template>
<Tabs.TabsContent :value="tabName">
<div class="grid gap-4 pt-6">
<div class="flex items-center justify-between gap-2">
<span> Credit Limit: </span>

{{ toLocalNumber(account.creditLimit) }}
{{ currenciesMap[account.currencyId].currency.code }}
</div>
<Separator />

<div class="flex items-center justify-between gap-2">
<span> Initial Balance: </span>

{{ toLocalNumber(account.initialBalance) }}
{{ currenciesMap[account.currencyId].currency.code }}
</div>
<Separator />
<div class="flex items-center justify-between gap-2">
<span> Account Type: </span>

{{ account.type }}
</div>
<Separator />

<Collapsible.Collapsible v-model:open="isOpen">
<Collapsible.CollapsibleTrigger class="w-full">
<div class="flex items-center justify-between gap-2">
<span> Currency: </span>

<div class="flex gap-2">
{{ currenciesMap[account.currencyId].currency.code }}

<span v-if="currenciesMap[account.currencyId].isDefaultCurrency">
(main)
</span>

<template v-if="isOpen">
<ChevronUpIcon />
</template>
<template v-else>
<ChevronDownIcon />
</template>
</div>
</div>
</Collapsible.CollapsibleTrigger>

<Collapsible.CollapsibleContent>
<div class="grid gap-2 pt-4 pl-4">
<Separator />

<div class="flex items-center justify-between gap-2">
<span> Exchange Rate: </span>

{{ currenciesMap[account.currencyId].exchangeRate }}
</div>

<Separator />

<div class="flex items-center justify-between gap-2">
<span> Exchange Rate Live Update: </span>

{{
currenciesMap[account.currencyId].liveRateUpdate
? "Enabled"
: "Disabled"
}}
</div>
</div>
</Collapsible.CollapsibleContent>
</Collapsible.Collapsible>
</div>
</Tabs.TabsContent>
</template>
75 changes: 75 additions & 0 deletions src/pages/account/components/setting-toggle-visibility.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<script setup lang="ts">
import { debounce } from "lodash-es";
import { reactive, watchEffect, watch } from "vue";
import { AccountModel } from "shared-types";
import { Switch } from "@/components/lib/ui/switch";
import { useAccountsStore } from "@/stores";
import {
useNotificationCenter,
NotificationType,
} from "@/components/notification-center";
const props = defineProps<{
account: AccountModel;
}>();
const { addNotification } = useNotificationCenter();
const accountsStore = useAccountsStore();
const form = reactive({
isEnabled: false,
});
const updateVisibility = async ({
id,
isEnabled,
}: {
id: number;
isEnabled: boolean;
}) => {
try {
await accountsStore.editAccount({ id, isEnabled });
addNotification({
text: "Updated successfully",
type: NotificationType.success,
});
} catch (err) {
addNotification({
text: "Unexpected error",
type: NotificationType.error,
});
form.isEnabled = !form.isEnabled;
}
};
const debouncedUpdateMonoAccHandler = debounce(updateVisibility, 1000);
watchEffect(() => {
if (props.account) {
form.isEnabled = props.account.isEnabled;
}
});
watch(
() => form.isEnabled,
(value) => {
if (value !== props.account.isEnabled) {
debouncedUpdateMonoAccHandler({
id: props.account.id,
isEnabled: value,
});
}
},
{ immediate: true },
);
</script>

<template>
<div class="flex items-center justify-between gap-2">
<span> Make this account visible on the Dashboard: </span>

<Switch v-model:checked="form.isEnabled" />
</div>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<Button
:disabled="isRefreshDisabled"
class="min-w-[100px]"
size="sm"
@click="loadLatestTransactionsHandler"
>
{{ isRefreshDisabled ? "Loading..." : "Load" }}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/account/types/monobank/load-transactions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const loadTransactionsForPeriod = async () => {
@update:open="selectorVisible = $event"
>
<Popover.PopoverTrigger>
<Button class="min-w-[100px]"> Select period </Button>
<Button class="min-w-[100px]" size="sm"> Select period </Button>
</Popover.PopoverTrigger>

<Popover.PopoverContent class="w-[600px] grid gap-3">
Expand Down
163 changes: 13 additions & 150 deletions src/pages/account/types/monobank/monobank.vue
Original file line number Diff line number Diff line change
@@ -1,82 +1,16 @@
<script setup lang="ts">
import { debounce } from "lodash-es";
import { reactive, watchEffect, watch, ref } from "vue";
import { storeToRefs } from "pinia";
import { ACCOUNT_TYPES, AccountModel } from "shared-types";
import { ChevronDownIcon, ChevronUpIcon } from "lucide-vue-next";
import * as Tabs from "@/components/lib/ui/tabs";
import * as Collapsible from "@/components/lib/ui/collapsible";
import { Switch } from "@/components/lib/ui/switch";
import { Separator } from "@/components/lib/ui/separator";
import { useAccountsStore, useCurrenciesStore } from "@/stores";
import { toLocalNumber } from "@/js/helpers";
import {
useNotificationCenter,
NotificationType,
} from "@/components/notification-center";
import AccountDetailsTab from "@/pages/account/components/account-details-tab.vue";
import SettingToggleVisibility from "@/pages/account/components/setting-toggle-visibility.vue";
import LoadLatestTransactions from "./load-latest-transactions.vue";
import LoadTransactions from "./load-transactions.vue";
const props = defineProps<{
defineProps<{
account: AccountModel;
}>();
const { addNotification } = useNotificationCenter();
const accountsStore = useAccountsStore();
const { currenciesMap, baseCurrency } = storeToRefs(useCurrenciesStore());
const form = reactive({
isEnabled: false,
period: null,
});
const updateVisibility = async ({
id,
isEnabled,
}: {
id: number;
isEnabled: boolean;
}) => {
try {
await accountsStore.editAccount({ id, isEnabled });
addNotification({
text: "Updated successfully",
type: NotificationType.success,
});
} catch (err) {
addNotification({
text: "Unexpected error",
type: NotificationType.error,
});
form.isEnabled = !form.isEnabled;
}
};
const isOpen = ref(false);
const debouncedUpdateMonoAccHandler = debounce(updateVisibility, 1000);
watchEffect(() => {
if (props.account) {
form.isEnabled = props.account.isEnabled;
}
});
watch(
() => form.isEnabled,
(value) => {
if (value !== props.account.isEnabled) {
debouncedUpdateMonoAccHandler({
id: props.account.id,
isEnabled: value,
});
}
},
{ immediate: true },
);
</script>

<template>
Expand All @@ -86,93 +20,22 @@ watch(
<Tabs.TabsTrigger value="settings"> Settings </Tabs.TabsTrigger>
</Tabs.TabsList>

<Tabs.TabsContent value="details" class="grid gap-4 pt-6">
<div class="flex items-center justify-between gap-2">
<span> Credit Limit: </span>

{{ toLocalNumber(account.creditLimit) }}
{{ baseCurrency.currency.code }}
</div>
<Separator />
<div class="flex items-center justify-between gap-2">
<span> Account Type: </span>

{{ account.type }}
</div>
<Separator />

<Collapsible.Collapsible v-model:open="isOpen">
<Collapsible.CollapsibleTrigger class="w-full">
<div class="flex items-center justify-between gap-2">
<span> Currency: </span>

<div class="flex gap-2">
{{ currenciesMap[account.currencyId].currency.code }}
<AccountDetailsTab tab-name="details" :account="account" />

<span v-if="currenciesMap[account.currencyId].isDefaultCurrency">
(main)
</span>
<Tabs.TabsContent value="settings">
<div class="grid gap-4 pt-6">
<SettingToggleVisibility :account="account" />

<template v-if="isOpen">
<ChevronUpIcon />
</template>
<template v-else>
<ChevronDownIcon />
</template>
</div>
</div>
</Collapsible.CollapsibleTrigger>
<Separator />

<Collapsible.CollapsibleContent>
<div class="grid gap-2 pt-4 pl-4">
<Separator />
<template v-if="account.type === ACCOUNT_TYPES.monobank">
<LoadLatestTransactions :account="account" />
</template>

<div class="flex items-center justify-between gap-2">
<span> Exchange Rate: </span>
<Separator />

{{ currenciesMap[account.currencyId].exchangeRate }}
</div>

<Separator />

<div class="flex items-center justify-between gap-2">
<span> Exchange Rate Live Update: </span>

{{
currenciesMap[account.currencyId].liveRateUpdate
? "Enabled"
: "Disabled"
}}
</div>
</div>
</Collapsible.CollapsibleContent>
</Collapsible.Collapsible>

<Separator />

<div class="flex items-center justify-between gap-2">
<span> Live update enabled? </span>

{{ currenciesMap[account.currencyId].liveRateUpdate }}
</div>
</Tabs.TabsContent>

<Tabs.TabsContent value="settings" class="grid gap-4 pt-6">
<div class="flex items-center justify-between gap-2">
<span> Make this account visible on the Dashboard: </span>

<Switch v-model:checked="form.isEnabled" />
<LoadTransactions :account="account" />
</div>

<Separator />

<template v-if="account.type === ACCOUNT_TYPES.monobank">
<LoadLatestTransactions :account="account" />
</template>

<Separator />

<LoadTransactions :account="account" />
</Tabs.TabsContent>
</Tabs.Tabs>
</template>
Loading

0 comments on commit e789e59

Please sign in to comment.