Fix :Forms Floating Actions.

This commit is contained in:
elforjani3
2020-11-25 23:05:37 +02:00
parent 7c16cb2b24
commit 33827f8ed2
8 changed files with 73 additions and 66 deletions

View File

@@ -124,7 +124,7 @@ function ExpensesDataTable({
text={formatMessage({ id: 'view_details' })} text={formatMessage({ id: 'view_details' })}
/> />
<MenuDivider /> <MenuDivider />
<If condition={!expense.published}> <If condition={!expense.is_published}>
<MenuItem <MenuItem
icon={<Icon icon={'arrow-to-top'} size={16} />} icon={<Icon icon={'arrow-to-top'} size={16} />}
text={formatMessage({ id: 'publish_expense' })} text={formatMessage({ id: 'publish_expense' })}
@@ -209,7 +209,7 @@ function ExpensesDataTable({
id: 'publish', id: 'publish',
Header: formatMessage({ id: 'publish' }), Header: formatMessage({ id: 'publish' }),
accessor: (r) => { accessor: (r) => {
return r.published ? ( return !!r.is_published ? (
<Tag minimal={true}> <Tag minimal={true}>
<T id={'published'} /> <T id={'published'} />
</Tag> </Tag>

View File

@@ -90,7 +90,7 @@ export default function ExpenseFloatingFooter({
return ( return (
<div className={classNames(CLASSES.PAGE_FORM_FLOATING_ACTIONS)}> <div className={classNames(CLASSES.PAGE_FORM_FLOATING_ACTIONS)}>
{/* ----------- Save And Publish ----------- */} {/* ----------- Save And Publish ----------- */}
<If condition={!expense}> <If condition={!expense || !expensePublished}>
<ButtonGroup> <ButtonGroup>
<Button <Button
disabled={isSubmitting} disabled={isSubmitting}

View File

@@ -129,6 +129,7 @@ function ExpenseForm({
description: '', description: '',
reference_no: '', reference_no: '',
currency_code: baseCurrency, currency_code: baseCurrency,
is_published: '',
categories: [...repeatValue(defaultCategory, MIN_LINES_NUMBER)], categories: [...repeatValue(defaultCategory, MIN_LINES_NUMBER)],
}), }),
[defaultCategory], [defaultCategory],
@@ -230,7 +231,7 @@ function ExpenseForm({
const form = { const form = {
...values, ...values,
publish: submitPayload.publish, is_published: submitPayload.publish,
categories, categories,
}; };
const saveExpense = (mdeiaIds) => const saveExpense = (mdeiaIds) =>
@@ -374,7 +375,7 @@ function ExpenseForm({
onSubmitForm={submitForm} onSubmitForm={submitForm}
onResetForm={resetForm} onResetForm={resetForm}
expense={expenseId} expense={expenseId}
expensePublished={true} expensePublished={values.is_published}
/> />
</form> </form>
</div> </div>

View File

@@ -21,7 +21,7 @@ const Schema = Yup.object().shape({
.max(DATATYPES_LENGTH.TEXT) .max(DATATYPES_LENGTH.TEXT)
.nullable() .nullable()
.label(formatMessage({ id: 'description' })), .label(formatMessage({ id: 'description' })),
publish: Yup.boolean().label(formatMessage({ id: 'publish' })), is_published: Yup.boolean(),
categories: Yup.array().of( categories: Yup.array().of(
Yup.object().shape({ Yup.object().shape({
index: Yup.number().min(1).max(DATATYPES_LENGTH.INT_10).nullable(), index: Yup.number().min(1).max(DATATYPES_LENGTH.INT_10).nullable(),

View File

@@ -89,7 +89,7 @@ export default function EstimateFloatingActions({
return ( return (
<div className={classNames(CLASSES.PAGE_FORM_FLOATING_ACTIONS)}> <div className={classNames(CLASSES.PAGE_FORM_FLOATING_ACTIONS)}>
{/* ----------- Save And Publish ----------- */} {/* ----------- Save And Publish ----------- */}
<If condition={!estimateId}> <If condition={!estimateId || !estimatePublished}>
<ButtonGroup> <ButtonGroup>
<Button <Button
disabled={isSubmitting} disabled={isSubmitting}

View File

@@ -89,7 +89,7 @@ export default function InvoiceFloatingActions({
return ( return (
<div className={classNames(CLASSES.PAGE_FORM_FLOATING_ACTIONS)}> <div className={classNames(CLASSES.PAGE_FORM_FLOATING_ACTIONS)}>
{/* ----------- Save And Publish ----------- */} {/* ----------- Save And Publish ----------- */}
<If condition={!invoice}> <If condition={!invoice || !invoicePublished}>
<ButtonGroup> <ButtonGroup>
<Button <Button
disabled={isSubmitting} disabled={isSubmitting}

View File

@@ -89,7 +89,7 @@ export default function ReceiptFormFloatingActions({
return ( return (
<div className={classNames(CLASSES.PAGE_FORM_FLOATING_ACTIONS)}> <div className={classNames(CLASSES.PAGE_FORM_FLOATING_ACTIONS)}>
{/* ----------- Save And Publish ----------- */} {/* ----------- Save And Publish ----------- */}
<If condition={!receiptId}> <If condition={!receiptId || !receiptPublished}>
<ButtonGroup> <ButtonGroup>
<Button <Button
disabled={isSubmitting} disabled={isSubmitting}

View File

@@ -1,28 +1,28 @@
import { Model } from 'objection'; import { Model } from "objection";
import TenantModel from 'models/TenantModel'; import TenantModel from "models/TenantModel";
import { viewRolesBuilder } from 'lib/ViewRolesBuilder'; import { viewRolesBuilder } from "lib/ViewRolesBuilder";
import Media from './Media'; import Media from "./Media";
export default class Expense extends TenantModel { export default class Expense extends TenantModel {
/** /**
* Table name * Table name
*/ */
static get tableName() { static get tableName() {
return 'expenses_transactions'; return "expenses_transactions";
} }
/** /**
* Account transaction reference type. * Account transaction reference type.
*/ */
static get referenceType() { static get referenceType() {
return 'Expense'; return "Expense";
} }
/** /**
* Model timestamps. * Model timestamps.
*/ */
get timestamps() { get timestamps() {
return ['createdAt', 'updatedAt']; return ["createdAt", "updatedAt"];
} }
/** /**
@@ -33,11 +33,18 @@ export default class Expense extends TenantModel {
} }
/** /**
* *
*/ */
static get media () { static get media() {
return true; return true;
} }
static get virtualAttributes() {
return ["isPublished"];
}
isPublished() {
return Boolean(this.publishedAt);
}
/** /**
* Model modifiers. * Model modifiers.
@@ -46,28 +53,28 @@ export default class Expense extends TenantModel {
return { return {
filterByDateRange(query, startDate, endDate) { filterByDateRange(query, startDate, endDate) {
if (startDate) { if (startDate) {
query.where('date', '>=', startDate); query.where("date", ">=", startDate);
} }
if (endDate) { if (endDate) {
query.where('date', '<=', endDate); query.where("date", "<=", endDate);
} }
}, },
filterByAmountRange(query, from, to) { filterByAmountRange(query, from, to) {
if (from) { if (from) {
query.where('amount', '>=', from); query.where("amount", ">=", from);
} }
if (to) { if (to) {
query.where('amount', '<=', to); query.where("amount", "<=", to);
} }
}, },
filterByExpenseAccount(query, accountId) { filterByExpenseAccount(query, accountId) {
if (accountId) { if (accountId) {
query.where('expense_account_id', accountId); query.where("expense_account_id", accountId);
} }
}, },
filterByPaymentAccount(query, accountId) { filterByPaymentAccount(query, accountId) {
if (accountId) { if (accountId) {
query.where('payment_account_id', accountId); query.where("payment_account_id", accountId);
} }
}, },
viewRolesBuilder(query, conditionals, expression) { viewRolesBuilder(query, conditionals, expression) {
@@ -80,41 +87,41 @@ export default class Expense extends TenantModel {
* Relationship mapping. * Relationship mapping.
*/ */
static get relationMappings() { static get relationMappings() {
const Account = require('models/Account'); const Account = require("models/Account");
const ExpenseCategory = require('models/ExpenseCategory'); const ExpenseCategory = require("models/ExpenseCategory");
const Media = require('models/Media'); const Media = require("models/Media");
return { return {
paymentAccount: { paymentAccount: {
relation: Model.BelongsToOneRelation, relation: Model.BelongsToOneRelation,
modelClass: Account.default, modelClass: Account.default,
join: { join: {
from: 'expenses_transactions.paymentAccountId', from: "expenses_transactions.paymentAccountId",
to: 'accounts.id', to: "accounts.id",
}, },
}, },
categories: { categories: {
relation: Model.HasManyRelation, relation: Model.HasManyRelation,
modelClass: ExpenseCategory.default, modelClass: ExpenseCategory.default,
join: { join: {
from: 'expenses_transactions.id', from: "expenses_transactions.id",
to: 'expense_transaction_categories.expenseId', to: "expense_transaction_categories.expenseId",
}, },
}, },
media: { media: {
relation: Model.ManyToManyRelation, relation: Model.ManyToManyRelation,
modelClass: Media.default, modelClass: Media.default,
join: { join: {
from: 'expenses_transactions.id', from: "expenses_transactions.id",
through: { through: {
from: 'media_links.model_id', from: "media_links.model_id",
to: 'media_links.media_id', to: "media_links.media_id",
}, },
to: 'media.id', to: "media.id",
}, },
filter(query) { filter(query) {
query.where('model_name', 'Expense'); query.where("model_name", "Expense");
} },
}, },
}; };
} }
@@ -125,51 +132,50 @@ export default class Expense extends TenantModel {
static get fields() { static get fields() {
return { return {
payment_date: { payment_date: {
label: 'Payment date', label: "Payment date",
column: 'payment_date', column: "payment_date",
columnType: 'date', columnType: "date",
}, },
payment_account: { payment_account: {
label: 'Payment account', label: "Payment account",
column: 'payment_account_id', column: "payment_account_id",
relation: 'accounts.id', relation: "accounts.id",
optionsResource: 'account', optionsResource: "account",
}, },
amount: { amount: {
label: 'Amount', label: "Amount",
column: 'total_amount', column: "total_amount",
columnType: 'number' columnType: "number",
}, },
currency_code: { currency_code: {
label: 'Currency', label: "Currency",
column: 'currency_code', column: "currency_code",
optionsResource: 'currency', optionsResource: "currency",
}, },
reference_no: { reference_no: {
label: 'Reference No.', label: "Reference No.",
column: 'reference_no', column: "reference_no",
columnType: 'string', columnType: "string",
}, },
description: { description: {
label: 'Description', label: "Description",
column: 'description', column: "description",
columnType: 'string', columnType: "string",
}, },
published: { published: {
label: 'Published', label: "Published",
column: 'published', column: "published",
}, },
user: { user: {
label: 'User', label: "User",
column: 'user_id', column: "user_id",
relation: 'users.id', relation: "users.id",
relationColumn: 'users.id', relationColumn: "users.id",
}, },
created_at: { created_at: {
label: 'Created at', label: "Created at",
column: 'created_at', column: "created_at",
columnType: 'date', columnType: "date",
}, },
}; };
} }