-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
231 additions
and
263 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
75
src/pages/account/components/setting-toggle-visibility.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.