Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create finance tracker #4956

Closed
wants to merge 1 commit into from
Closed

Create finance tracker #4956

wants to merge 1 commit into from

Conversation

vijayleo31
Copy link

@vijayleo31 vijayleo31 commented Nov 26, 2024

Description

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Checklist

ℹ️ Check all checkboxes - this will indicate that you have done everything in accordance with the rules in CONTRIBUTING.

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs:dev command.
  • Run the tests with pnpm test.
  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Summary by CodeRabbit

  • New Features
    • Introduced a personal finance tracker application with a structured project setup.
    • Implemented routing for home, login, and registration pages.
    • Added state management for transactions using Vuex, including functionality to add and delete transactions.
    • Created forms for submitting transactions with input fields for amount and category.
    • Included a template for displaying transaction data in a bar chart format.

Copy link

changeset-bot bot commented Nov 26, 2024

⚠️ No Changeset found

Latest commit: 735909c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Nov 26, 2024

Walkthrough

The changes introduce a new Vue.js application designed for personal finance tracking. This includes the establishment of project structure, installation of dependencies like vue-router, vuex, and chart.js, and configuration of a router with three routes: home, login, and registration. A Vuex store is implemented to manage transaction states, including methods for adding and deleting transactions. Additionally, two form components for transaction submission are created, along with a template for a bar chart, although the chart component's import is incomplete.

Changes

File Path Change Summary
src/router/index.js Created router instance with three routes: home, login, registration.
src/store/index.js Created Vuex store instance; added methods for addTransaction and deleteTransaction; added getter for allTransactions.
src/components/TransactionForm.vue Implemented two identical form components for submitting transactions; includes input fields and submission logic.
src/components/BarChart.vue Included a template for displaying a bar chart; import statement for chart component is incomplete.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Frontend
    participant VuexStore

    User->>Frontend: Submit Transaction
    Frontend->>VuexStore: dispatch addTransaction
    VuexStore-->>Frontend: Transaction added
    Frontend->>User: Clear input fields
Loading

🐰 "In the garden of finance, we hop and play,
With charts and forms, we track our way.
Transactions added, oh what a sight,
In our new app, everything feels right!
So gather 'round, let's celebrate,
A bunny's joy in tracking fate!" 🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@vijayleo31
Copy link
Author

tracker

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Outside diff range and nitpick comments (1)
finance tracker (1)

1-126: Consider implementing data persistence and API integration.

The current implementation stores data in memory and localStorage. For a production finance tracker:

  1. Implement a backend API for data persistence
  2. Add user authentication and authorization
  3. Consider implementing real-time updates using WebSocket
  4. Add data export functionality
  5. Implement proper error boundaries and logging

Would you like assistance in designing the API architecture and data models?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between f85badf and 735909c.

📒 Files selected for processing (1)
  • finance tracker (1 hunks)

Comment on lines +1 to +3
vue create personal-finance-tracker
cd personal-finance-tracker
npm install vue-router vuex chart.js vue-chartjs
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Pin dependency versions for better reproducibility.

Installing dependencies without version specifications can lead to compatibility issues. Consider pinning specific versions:

-npm install vue-router vuex chart.js vue-chartjs
+npm install [email protected] [email protected] [email protected] [email protected]

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +13 to +22
const routes = [
{ path: '/', component: Home },
{ path: '/login', component: Login },
{ path: '/register', component: Register },
];

const router = new Router({
mode: 'history',
routes,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance router configuration with authentication and error handling.

The current router configuration lacks several important features:

  1. Authentication guards for protected routes
  2. 404 route handler for invalid paths
  3. Route meta information for auth requirements
 const routes = [
-  { path: '/', component: Home },
-  { path: '/login', component: Login },
-  { path: '/register', component: Register },
+  { 
+    path: '/', 
+    component: Home,
+    meta: { requiresAuth: true }
+  },
+  { 
+    path: '/login',
+    component: Login,
+    meta: { guest: true }
+  },
+  { 
+    path: '/register',
+    component: Register,
+    meta: { guest: true }
+  },
+  { 
+    path: '*',
+    component: () => import('../views/NotFound.vue')
+  }
 ];

 const router = new Router({
   mode: 'history',
   routes,
 });
+
+router.beforeEach((to, from, next) => {
+  const isAuthenticated = store.getters.isAuthenticated;
+  
+  if (to.matched.some(record => record.meta.requiresAuth)) {
+    if (!isAuthenticated) {
+      next('/login');
+    } else {
+      next();
+    }
+  } else if (to.matched.some(record => record.meta.guest)) {
+    if (isAuthenticated) {
+      next('/');
+    } else {
+      next();
+    }
+  } else {
+    next();
+  }
+});

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +119 to +126
<template>
<div>
<bar-chart :chart-data="chartData"></bar-chart>
</div>
</template>

<script>
import { Bar }
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Complete the chart component implementation.

The chart component is incomplete. The import statement is cut off and chart configuration is missing.

Here's a complete implementation:

 <template>
   <div>
+    <div v-if="loading">Loading...</div>
+    <div v-else-if="error">{{ error }}</div>
     <bar-chart :chart-data="chartData"></bar-chart>
   </div>
 </template>

 <script>
-import { Bar }
+import { Bar } from 'vue-chartjs';
+import { 
+  Chart as ChartJS,
+  Title,
+  Tooltip,
+  Legend,
+  BarElement,
+  CategoryScale,
+  LinearScale
+} from 'chart.js';
+
+ChartJS.register(
+  Title,
+  Tooltip,
+  Legend,
+  BarElement,
+  CategoryScale,
+  LinearScale
+);
+
+export default {
+  components: {
+    BarChart: Bar
+  },
+  data() {
+    return {
+      loading: false,
+      error: null
+    };
+  },
+  computed: {
+    chartData() {
+      const transactions = this.$store.getters.allTransactions;
+      const categories = [...new Set(transactions.map(t => t.category))];
+      
+      return {
+        labels: categories,
+        datasets: [{
+          label: 'Spending by Category',
+          data: categories.map(category => 
+            transactions
+              .filter(t => t.category === category)
+              .reduce((sum, t) => sum + t.amount, 0)
+          ),
+          backgroundColor: 'rgba(75, 192, 192, 0.2)',
+          borderColor: 'rgba(75, 192, 192, 1)',
+          borderWidth: 1
+        }]
+      };
+    }
+  }
+};
+</script>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<template>
<div>
<bar-chart :chart-data="chartData"></bar-chart>
</div>
</template>
<script>
import { Bar }
<template>
<div>
<div v-if="loading">Loading...</div>
<div v-else-if="error">{{ error }}</div>
<bar-chart :chart-data="chartData"></bar-chart>
</div>
</template>
<script>
import { Bar } from 'vue-chartjs';
import {
Chart as ChartJS,
Title,
Tooltip,
Legend,
BarElement,
CategoryScale,
LinearScale
} from 'chart.js';
ChartJS.register(
Title,
Tooltip,
Legend,
BarElement,
CategoryScale,
LinearScale
);
export default {
components: {
BarChart: Bar
},
data() {
return {
loading: false,
error: null
};
},
computed: {
chartData() {
const transactions = this.$store.getters.allTransactions;
const categories = [...new Set(transactions.map(t => t.category))];
return {
labels: categories,
datasets: [{
label: 'Spending by Category',
data: categories.map(category =>
transactions
.filter(t => t.category === category)
.reduce((sum, t) => sum + t.amount, 0)
),
backgroundColor: 'rgba(75, 192, 192, 0.2)',
borderColor: 'rgba(75, 192, 192, 1)',
borderWidth: 1
}]
};
}
}
};
</script>

Comment on lines +56 to +117
<template>
<form @submit.prevent="submitTransaction">
<input v-model="amount" type="number" placeholder="Amount" required />
<input v-model="category" type="text" placeholder="Category" required />
<button type="submit">Add Transaction</button>
</form>
</template>

<script>
export default {
data() {
return {
amount: '',
category: '',
};
},
methods: {
submitTransaction() {
const transaction = {
id: Date.now(),
amount: parseFloat(this.amount),
category: this.category,
};
this.$store.dispatch('addTransaction', transaction);
this.amount = '';
this.category = '';
},
},
};
</script>


<template>
<form @submit.prevent="submitTransaction">
<input v-model="amount" type="number" placeholder="Amount" required />
<input v-model="category" type="text" placeholder="Category" required />
<button type="submit">Add Transaction</button>
</form>
</template>

<script>
export default {
data() {
return {
amount: '',
category: '',
};
},
methods: {
submitTransaction() {
const transaction = {
id: Date.now(),
amount: parseFloat(this.amount),
category: this.category,
};
this.$store.dispatch('addTransaction', transaction);
this.amount = '';
this.category = '';
},
},
};
</script>
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Critical: Remove duplicated component and enhance form validation.

There are two identical form components which violates the DRY principle. Additionally, the form implementation has several issues:

  1. Weak ID generation using Date.now()
  2. Basic input validation
  3. No user feedback
  4. No loading states

Keep one component and enhance it:

 <template>
   <form @submit.prevent="submitTransaction">
+    <div v-if="error" class="error">{{ error }}</div>
     <input 
       v-model.number="amount" 
       type="number" 
       placeholder="Amount" 
+      :disabled="loading"
+      min="0.01"
+      step="0.01"
       required 
     />
     <input 
       v-model="category" 
       type="text" 
       placeholder="Category" 
+      :disabled="loading"
+      pattern="[A-Za-z ]+"
+      title="Only letters and spaces allowed"
       required 
     />
-    <button type="submit">Add Transaction</button>
+    <button type="submit" :disabled="loading">
+      {{ loading ? 'Adding...' : 'Add Transaction' }}
+    </button>
   </form>
 </template>

 <script>
+import { v4 as uuidv4 } from 'uuid';
+
 export default {
   data() {
     return {
       amount: '',
       category: '',
+      error: null
     };
   },
+  computed: {
+    loading() {
+      return this.$store.getters.isLoading;
+    }
+  },
   methods: {
-    submitTransaction() {
+    async submitTransaction() {
+      this.error = null;
+      
+      if (this.amount <= 0) {
+        this.error = 'Amount must be greater than 0';
+        return;
+      }
+      
       const transaction = {
-        id: Date.now(),
+        id: uuidv4(),
         amount: parseFloat(this.amount),
         category: this.category,
+        timestamp: new Date().toISOString()
       };
-      this.$store.dispatch('addTransaction', transaction);
-      this.amount = '';
-      this.category = '';
+      
+      try {
+        await this.$store.dispatch('addTransaction', transaction);
+        this.amount = '';
+        this.category = '';
+        this.$emit('transaction-added', transaction);
+      } catch (error) {
+        this.error = error.message;
+      }
     },
   },
 };
 </script>

+<style scoped>
+.error {
+  color: red;
+  margin-bottom: 1rem;
+}
+</style>

Consider extracting the validation logic into a separate utility function for reusability.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<template>
<form @submit.prevent="submitTransaction">
<input v-model="amount" type="number" placeholder="Amount" required />
<input v-model="category" type="text" placeholder="Category" required />
<button type="submit">Add Transaction</button>
</form>
</template>
<script>
export default {
data() {
return {
amount: '',
category: '',
};
},
methods: {
submitTransaction() {
const transaction = {
id: Date.now(),
amount: parseFloat(this.amount),
category: this.category,
};
this.$store.dispatch('addTransaction', transaction);
this.amount = '';
this.category = '';
},
},
};
</script>
<template>
<form @submit.prevent="submitTransaction">
<input v-model="amount" type="number" placeholder="Amount" required />
<input v-model="category" type="text" placeholder="Category" required />
<button type="submit">Add Transaction</button>
</form>
</template>
<script>
export default {
data() {
return {
amount: '',
category: '',
};
},
methods: {
submitTransaction() {
const transaction = {
id: Date.now(),
amount: parseFloat(this.amount),
category: this.category,
};
this.$store.dispatch('addTransaction', transaction);
this.amount = '';
this.category = '';
},
},
};
</script>
<template>
<form @submit.prevent="submitTransaction">
<div v-if="error" class="error">{{ error }}</div>
<input
v-model.number="amount"
type="number"
placeholder="Amount"
:disabled="loading"
min="0.01"
step="0.01"
required
/>
<input
v-model="category"
type="text"
placeholder="Category"
:disabled="loading"
pattern="[A-Za-z ]+"
title="Only letters and spaces allowed"
required
/>
<button type="submit" :disabled="loading">
{{ loading ? 'Adding...' : 'Add Transaction' }}
</button>
</form>
</template>
<script>
import { v4 as uuidv4 } from 'uuid';
export default {
data() {
return {
amount: '',
category: '',
error: null
};
},
computed: {
loading() {
return this.$store.getters.isLoading;
}
},
methods: {
async submitTransaction() {
this.error = null;
if (this.amount <= 0) {
this.error = 'Amount must be greater than 0';
return;
}
const transaction = {
id: uuidv4(),
amount: parseFloat(this.amount),
category: this.category,
timestamp: new Date().toISOString()
};
try {
await this.$store.dispatch('addTransaction', transaction);
this.amount = '';
this.category = '';
this.$emit('transaction-added', transaction);
} catch (error) {
this.error = error.message;
}
},
},
};
</script>
<style scoped>
.error {
color: red;
margin-bottom: 1rem;
}
</style>

Comment on lines +31 to +54
export default new Vuex.Store({
state: {
transactions: [],
},
mutations: {
ADD_TRANSACTION(state, transaction) {
state.transactions.push(transaction);
},
DELETE_TRANSACTION(state, transactionId) {
state.transactions = state.transactions.filter(t => t.id !== transactionId);
},
},
actions: {
addTransaction({ commit }, transaction) {
commit('ADD_TRANSACTION', transaction);
},
deleteTransaction({ commit }, transactionId) {
commit('DELETE_TRANSACTION', transactionId);
},
},
getters: {
allTransactions: state => state.transactions,
},
});
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance store with persistence, validation, and error handling.

The current store implementation lacks several critical features:

  1. Data persistence
  2. Transaction validation
  3. Loading states
  4. Error handling
 export default new Vuex.Store({
   state: {
     transactions: [],
+    loading: false,
+    error: null
   },
   mutations: {
     ADD_TRANSACTION(state, transaction) {
+      if (!transaction.amount || !transaction.category) {
+        throw new Error('Invalid transaction data');
+      }
       state.transactions.push(transaction);
+      localStorage.setItem('transactions', JSON.stringify(state.transactions));
     },
     DELETE_TRANSACTION(state, transactionId) {
       state.transactions = state.transactions.filter(t => t.id !== transactionId);
+      localStorage.setItem('transactions', JSON.stringify(state.transactions));
     },
+    SET_LOADING(state, status) {
+      state.loading = status;
+    },
+    SET_ERROR(state, error) {
+      state.error = error;
+    }
   },
   actions: {
-    addTransaction({ commit }, transaction) {
-      commit('ADD_TRANSACTION', transaction);
+    async addTransaction({ commit }, transaction) {
+      try {
+        commit('SET_LOADING', true);
+        commit('SET_ERROR', null);
+        // Add API call here when backend is ready
+        commit('ADD_TRANSACTION', transaction);
+      } catch (error) {
+        commit('SET_ERROR', error.message);
+      } finally {
+        commit('SET_LOADING', false);
+      }
     },
-    deleteTransaction({ commit }, transactionId) {
-      commit('DELETE_TRANSACTION', transactionId);
+    async deleteTransaction({ commit }, transactionId) {
+      try {
+        commit('SET_LOADING', true);
+        commit('SET_ERROR', null);
+        // Add API call here when backend is ready
+        commit('DELETE_TRANSACTION', transactionId);
+      } catch (error) {
+        commit('SET_ERROR', error.message);
+      } finally {
+        commit('SET_LOADING', false);
+      }
     },
+    initializeStore({ commit }) {
+      const stored = localStorage.getItem('transactions');
+      if (stored) {
+        commit('SET_TRANSACTIONS', JSON.parse(stored));
+      }
+    }
   },
   getters: {
     allTransactions: state => state.transactions,
+    isLoading: state => state.loading,
+    hasError: state => state.error !== null,
+    getError: state => state.error
   },
 });

Committable suggestion skipped: line range outside the PR's diff.

@doraemonxxx
Copy link

Please close this PR 🤷

@anncwb anncwb closed this Dec 1, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jan 1, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants