#29 Adding A New Accounts Details View For Editing And Creating Accounts
Sunday, December 22, 2019
In this article we will focus on creating a new accounts details page which will allow us to create and edit accounts. We will start by adding the ability to route to the new page using our routing system. Along the way we will make a few updates to a couple of our previously created types so that their names will be inline with the conventions we have developed. We will then finish up by using the infrastructure that we have developed along the way to quickly add some basic functionality to our newly created details view.
Parts
- Part 45: Adjusting Shares
- Part 44: Plan Percentages
- Part 43: Home Securities
- Part 42: Updating Plans
- Part 41: Plan Details View
- Part 40: Portfolio Getters
- Part 39: Portfolio Plan
- Part 38: Portfolio Category
- Part 37: Account Securities
- Part 36: Account Transfer
- Part 35: View Account Security
- Part 34: Updating Deposit
- Part 33: View Account Deposit
- Part 32: Display Account Details
- Part 31: Account Getters
- Part 30: Deposits And Securities
- Part 29: Add Accounts Details
- Part 28: Refactoring Accounts
- Part 27: Add Security Models
- Part 26: Edit Security Details
- Part 25: View Security Details
- Part 24: Navigating To Details
- Part 23: Getters Validation
- Part 22: Query Parameters
- Part 21: Tab Entries
- Part 20: Tab Header
- Part 19: List View
- Part 18: Vuex Getters
- Part 17: End Domain Model
- Part 16: Start Domain Model
- Part 15: Pop Routes
- Part 14: Push Routes
- Part 13: Removing Accounts
- Part 12: Vuex (Decorators)
- Part 11: Vuex (Accounts)
- Part 10: The App Bar (Settings)
- Part 9: Remove Consumer Rxjs
- Part 8: The App Bar (Back)
- Part 7: Structuring Our App
- Part 6: Animation Between Views
- Part 5: Navigation Fade
- Part 4: Navigation Requests
- Part 3: Fade Animations (cont.)
- Part 2: Fade Animations
- Part 1: Splash Screen
Code Snippets
AccountsDetails.vue (1:29)
<template lang="pug">
div accounts details
</template>
AccountsDetails.vue (1:29)
<script lang="tsx">
import { Component, Vue } from "vue-property-decorator";
@Component
export default class AccountsDetails extends Vue {
}
</script>
types.ts (1:55)
...
export enum Routes {
...
AccountsDetails,
...
}
...
routing-service.ts (2:07)
...
const accountsDetails = new RouteEntry({
component: () => import(/* webpackChunkName: "accounts-details" */ "../../views/AccountsDetails.vue"),
name: "accounts-details",
parent: accounts,
path: "/accounts-details",
route: Routes.AccountsDetails,
});
...
export class RoutingService {
...
private readonly _routes = [..., accountsDetails, ...];
...
}
Accounts.vue (3:06)
<script lang="tsx">
...
export default class Accounts extends Vue {
...
private onClick(account: AccountModel) {
this.routingService.navigateTo(Routes.AccountsDetails, {
query: { id: `${account.id}` },
});
}
private onClickCreate() {
this.routingService.navigateTo(Routes.AccountsDetails, {
query: { id: "0" },
});
}
...
}
</script>
route-types.ts (4:59)
...
export type PayloadPopRoute = void;
export type PayloadPushRoute = IRoute;
route-module.ts
...
import { PayloadPushRoute } from "@/store/route-types";
...
export const routeActions: StoreActionTree = {
...,
[ACTION_PUSH_ROUTE](this, { commit }, route: PayloadPushRoute) {
...
},
};
export const routeMutations: StoreMutationTree = {
...,
[MUTATION_PUSH_ROUTE](state: IStoreState, payload: PayloadPushRoute) {
...
},
};
...
Advertisement
TheRouterOutlet.vue (5:49)
<script lang="ts">
...
import { ..., PayloadPopRoute, PayloadPushRoute } from "@/store";
...
export default class TheRouterOutlet extends Vue {
@Action(ACTION_POP_ROUTE) private readonly popRoute!: ActionFn<PayloadPopRoute>;
@Action(ACTION_PUSH_ROUTE) private readonly pushRoute!: ActionFn<PayloadPushRoute>;
...
}
</script>
SecuritiesDetails.vue (6:22)
<script lang="ts">
...
import {
...,
PayloadPushRoute,
...,
} from "@/store";
...
export default class SecuritiesDetails extends Vue {
...
@Action(ACTION_PUSH_ROUTE) private readonly pushRoute!: ActionFn<PayloadPushRoute>;
...
}
</script>
routing-service.ts (7:16)
...
export class RoutingService {
...
public isPreviousRoute = (route: Routes) => {
if (this.history.length === 0) {
return false;
}
return this.history[0].id === route;
};
...
}
AccountsDetails.vue (8:19)
<script lang="tsx">
import { ..., Inject, ... } from "vue-property-decorator";
import DetailsActionButtons from "@/components/DetailsActionButtons.vue";
import { Routes, RoutingService } from "@/components/routing";
import { ACTION_PUSH_ROUTE, Action, ActionFn, GETTER_ACCOUNT, Getter, GetterAccount, PayloadPushRoute } from "@/store";
interface IQuery {
id: string;
}
@Component({
components: {
DetailsActionButtons,
}
})
export default class AccountsDetails extends Vue {
@Action(ACTION_PUSH_ROUTE) private readonly pushRoute!: ActionFn<PayloadPushRoute>;
@Getter(GETTER_ACCOUNT) private readonly getterAccount!: GetterAccount;
@Inject() private readonly routingService!: RoutingService;
private id = 0;
private name = "";
private created() {
if (this.routingService.isPreviousRoute(Routes.Accounts) === false) {
this.pushRoute(this.routingService.createRoute(Routes.Accounts));
}
this.id = this.routingService.queryParam<IQuery, number>((x) => x.id, parseInt);
if (this.id <= 0) {
return;
}
this.load();
}
private load() {
const account = this.getterAccount(this.id);
this.name = account.name;
}
private save() {
console.log("save");
}
}
</script>
AccountsDetails.vue (13:15)
<template lang="pug">
div
form
div.inputs
h1 Account Details
label Name
input(
type="text"
v-model="name")
DetailsActionButtons(v-bind:save="save")/
</template>
AccountsDetails.vue
<style lang="sass" scoped>
@import "../bourbon/bourbon"
@import "../bitters/functions"
@import "../bitters/variables"
.inputs
@include padding(null 0.25rem)
</style>
Exciton Interactive LLC