-
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.
Merge pull request #2 from ParadoxZero/sidhin/edit_categories_page
Implement edit categories page
- Loading branch information
Showing
15 changed files
with
523 additions
and
188 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
VITE_CREATE_DUMMY_DATA=false | ||
VITE_CREATE_DUMMY_DATA=true | ||
VITE_PING_REMOTE=false | ||
VITE_USE_LOCAL_DATA_SERVICE=true | ||
VITE_CLEAR_USER_DATA_ON_LOAD=true |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { Button, Card, Empty, Form, FormInstance, Input, InputNumber } from "antd"; | ||
import React from "react"; | ||
import { Budget, Category, DataModelFactory } from "../datamodel/datamodel"; | ||
import { navigation, store, View } from "../store"; | ||
import { CloseOutlined } from "@ant-design/icons"; | ||
import { DataService, getDataService } from "../services/data_service"; | ||
|
||
|
||
export interface EditCategoriesFormProps { | ||
budget_id: string; | ||
categories?: Category[]; | ||
onCategoriesAdded: () => void; | ||
onCancel: () => void; | ||
} | ||
|
||
interface EditCategoriesFormState { | ||
|
||
} | ||
|
||
export class AddCategoriesForm extends React.Component<EditCategoriesFormProps, EditCategoriesFormState> { | ||
data_service: DataService; | ||
|
||
constructor(props: EditCategoriesFormProps) { | ||
super(props); | ||
this.data_service = getDataService(); | ||
} | ||
|
||
render() { | ||
return ( | ||
this.render_add_category() | ||
); | ||
} | ||
|
||
render_add_category() { | ||
const formRef = React.createRef<FormInstance>(); | ||
const onFinish = (values: any) => { | ||
const category_list: Category[] = []; | ||
for (const raw_category of values.categories) { | ||
const category = DataModelFactory.createCategory(0); | ||
category.name = raw_category.name; | ||
category.allocation = raw_category.allocation; | ||
category_list.push(category); | ||
} | ||
this.setState({ is_loading: true }); | ||
this.data_service.createCategories(this.props.budget_id, category_list).then((value: Budget) => { | ||
this.props.onCategoriesAdded(); | ||
}).catch((_error: any) => { | ||
}); | ||
}; | ||
return ( | ||
<Form | ||
name="add_categories" | ||
style={{ maxWidth: 600 }} | ||
autoComplete="off" | ||
initialValues={{ categories: [] }} | ||
ref={formRef} | ||
onFinish={onFinish} | ||
> | ||
<Form.List name="categories"> | ||
{(fields, { add, remove }) => ( | ||
<div style={{ display: 'flex', rowGap: 16, flexDirection: 'column', justifyContent: 'center' }}> | ||
{fields.map((field) => ( | ||
<Card | ||
size="small" | ||
key={field.key} | ||
actions={[<CloseOutlined onClick={() => remove(field.name)} />]} | ||
> | ||
<Form.Item label="Name" name={[field.name, 'name']} rules={[{ required: true, message: "Name is required" }]}> | ||
<Input /> | ||
</Form.Item> | ||
<Form.Item label="Allocated Amount" name={[field.name, 'allocation']} rules={[{ required: true, message: "Allocation is required" }]}> | ||
<InputNumber type="number" inputMode="numeric" /> | ||
</Form.Item> | ||
</Card> | ||
))} | ||
{fields.length === 0 && ( | ||
<Empty description="No Categories Added" /> | ||
)} | ||
|
||
<Button type="dashed" onClick={() => add()} block> | ||
+ Add Category | ||
</Button> | ||
|
||
<Button type="primary" htmlType="submit" block> | ||
Finalize | ||
</Button> | ||
<Button type="link" onClick={() => this.props.onCancel()}>Cancel</Button> | ||
</div> | ||
)} | ||
</Form.List> | ||
</Form> | ||
); | ||
} | ||
} |
Oops, something went wrong.