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

Frontend: upload invoice #34

Open
wants to merge 14 commits into
base: feature/invoices-backend
Choose a base branch
from
3 changes: 2 additions & 1 deletion backend/src/graphql/resolvers/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ module.exports = {
});
return expenses;
},
transactions: (root, args, { models: { Transaction } }) => Transaction.find()
transactions: (root, args, { models: { Transaction } }) => Transaction.find(),
companies: (root, args, { models: { Company } }) => Company.find()
};
1 change: 1 addition & 0 deletions backend/src/graphql/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = gql`
me: User @auth
myExpenses: [Transaction]! @auth
transactions: [Transaction]! @auth
companies: [Company] @auth
}

type Mutation {
Expand Down
12 changes: 7 additions & 5 deletions frontend/components/ExpenseForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,12 @@ const ExpenseForm = () => {
const receipt = useInputFile({});
const [errors, setErrors] = useState({});
const variables = {
receipt: receipt.file.file,
amount: expense.fields.amount ? parseFloat(expense.fields.amount) : undefined,
description: expense.fields.description,
VAT: expense.fields.VAT ? parseInt(expense.fields.VAT, 10) : undefined
expense: {
receipt: receipt.file.file,
amount: expense.fields.amount ? parseFloat(expense.fields.amount) : undefined,
description: expense.fields.description,
VAT: expense.fields.VAT ? parseInt(expense.fields.VAT, 10) : undefined
}
};
const handleSubmit = (e, claim) => {
e.preventDefault();
Expand All @@ -116,7 +118,7 @@ const ExpenseForm = () => {
VAT: NON_NEGATIVE.rule
};

validateAll(variables, rules, messages)
validateAll(variables.expense, rules, messages)
.then(() => claim())
.catch(errs => {
setErrors(formatErrors(errs));
Expand Down
Loading