-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(invoice-ninja): add create client action
- Loading branch information
1 parent
497ce2e
commit 902cd39
Showing
7 changed files
with
346 additions
and
0 deletions.
There are no files selected for viewing
226 changes: 226 additions & 0 deletions
226
packages/backend/src/apps/invoice-ninja/actions/create-client/fields.ts
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,226 @@ | ||
export const fields = [ | ||
{ | ||
label: 'Client Name', | ||
key: 'clientName', | ||
type: 'string' as const, | ||
required: false, | ||
description: '', | ||
variables: true, | ||
}, | ||
{ | ||
label: 'Contact First Name', | ||
key: 'contactFirstName', | ||
type: 'string' as const, | ||
required: false, | ||
description: '', | ||
variables: true, | ||
}, | ||
{ | ||
label: 'Contact Last Name', | ||
key: 'contactLastName', | ||
type: 'string' as const, | ||
required: false, | ||
description: '', | ||
variables: true, | ||
}, | ||
{ | ||
label: 'Contact Email', | ||
key: 'contactEmail', | ||
type: 'string' as const, | ||
required: false, | ||
description: '', | ||
variables: true, | ||
}, | ||
{ | ||
label: 'Contact Phone', | ||
key: 'contactPhone', | ||
type: 'string' as const, | ||
required: false, | ||
description: '', | ||
variables: true, | ||
}, | ||
{ | ||
label: 'Language Code', | ||
key: 'languageCode', | ||
type: 'string' as const, | ||
required: false, | ||
description: '', | ||
variables: true, | ||
}, | ||
{ | ||
label: 'Currency Code', | ||
key: 'currencyCode', | ||
type: 'string' as const, | ||
required: false, | ||
description: '', | ||
variables: true, | ||
}, | ||
{ | ||
label: 'Id Number', | ||
key: 'idNumber', | ||
type: 'string' as const, | ||
required: false, | ||
description: '', | ||
variables: true, | ||
}, | ||
{ | ||
label: 'Vat Number', | ||
key: 'vatNumber', | ||
type: 'string' as const, | ||
required: false, | ||
description: '', | ||
variables: true, | ||
}, | ||
{ | ||
label: 'Street Address', | ||
key: 'streetAddress', | ||
type: 'string' as const, | ||
required: false, | ||
description: '', | ||
variables: true, | ||
}, | ||
{ | ||
label: 'Apt/Suite', | ||
key: 'aptSuite', | ||
type: 'string' as const, | ||
required: false, | ||
description: '', | ||
variables: true, | ||
}, | ||
{ | ||
label: 'City', | ||
key: 'city', | ||
type: 'string' as const, | ||
required: false, | ||
description: '', | ||
variables: true, | ||
}, | ||
{ | ||
label: 'State/Province', | ||
key: 'stateProvince', | ||
type: 'string' as const, | ||
required: false, | ||
description: '', | ||
variables: true, | ||
}, | ||
{ | ||
label: 'Postal Code', | ||
key: 'postalCode', | ||
type: 'string' as const, | ||
required: false, | ||
description: '', | ||
variables: true, | ||
}, | ||
{ | ||
label: 'Country Code', | ||
key: 'countryCode', | ||
type: 'string' as const, | ||
required: false, | ||
description: '', | ||
variables: true, | ||
}, | ||
{ | ||
label: 'Shipping Street Address', | ||
key: 'shippingStreetAddress', | ||
type: 'string' as const, | ||
required: false, | ||
description: '', | ||
variables: true, | ||
}, | ||
{ | ||
label: 'Shipping Apt/Suite', | ||
key: 'shippingAptSuite', | ||
type: 'string' as const, | ||
required: false, | ||
description: '', | ||
variables: true, | ||
}, | ||
{ | ||
label: 'Shipping City', | ||
key: 'shippingCity', | ||
type: 'string' as const, | ||
required: false, | ||
description: '', | ||
variables: true, | ||
}, | ||
{ | ||
label: 'Shipping State/Province', | ||
key: 'shippingStateProvince', | ||
type: 'string' as const, | ||
required: false, | ||
description: '', | ||
variables: true, | ||
}, | ||
{ | ||
label: 'Shipping Postal Code', | ||
key: 'shippingPostalCode', | ||
type: 'string' as const, | ||
required: false, | ||
description: '', | ||
variables: true, | ||
}, | ||
{ | ||
label: 'Shipping Country Code', | ||
key: 'shippingCountryCode', | ||
type: 'string' as const, | ||
required: false, | ||
description: '', | ||
variables: true, | ||
}, | ||
{ | ||
label: 'Private Notes', | ||
key: 'privateNotes', | ||
type: 'string' as const, | ||
required: false, | ||
description: '', | ||
variables: true, | ||
}, | ||
{ | ||
label: 'Public Notes', | ||
key: 'publicNotes', | ||
type: 'string' as const, | ||
required: false, | ||
description: '', | ||
variables: true, | ||
}, | ||
{ | ||
label: 'Website', | ||
key: 'website', | ||
type: 'string' as const, | ||
required: false, | ||
description: '', | ||
variables: true, | ||
}, | ||
{ | ||
label: 'Custom Value 1', | ||
key: 'customValue1', | ||
type: 'string' as const, | ||
required: false, | ||
description: '', | ||
variables: true, | ||
}, | ||
{ | ||
label: 'Custom Value 2', | ||
key: 'customValue2', | ||
type: 'string' as const, | ||
required: false, | ||
description: '', | ||
variables: true, | ||
}, | ||
{ | ||
label: 'Custom Value 3', | ||
key: 'customValue3', | ||
type: 'string' as const, | ||
required: false, | ||
description: '', | ||
variables: true, | ||
}, | ||
{ | ||
label: 'Custom Value 4', | ||
key: 'customValue4', | ||
type: 'string' as const, | ||
required: false, | ||
description: '', | ||
variables: true, | ||
}, | ||
]; |
84 changes: 84 additions & 0 deletions
84
packages/backend/src/apps/invoice-ninja/actions/create-client/index.ts
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,84 @@ | ||
import defineAction from '../../../../helpers/define-action'; | ||
import { filterProvidedFields } from '../../common/filter-provided-fields'; | ||
import { fields } from './fields'; | ||
|
||
export default defineAction({ | ||
name: 'Create client', | ||
key: 'createClient', | ||
description: 'Creates a new client.', | ||
arguments: fields, | ||
|
||
async run($) { | ||
const { | ||
clientName, | ||
contactFirstName, | ||
contactLastName, | ||
contactEmail, | ||
contactPhone, | ||
languageCode, | ||
currencyCode, | ||
idNumber, | ||
vatNumber, | ||
streetAddress, | ||
aptSuite, | ||
city, | ||
stateProvince, | ||
postalCode, | ||
countryCode, | ||
shippingStreetAddress, | ||
shippingAptSuite, | ||
shippingCity, | ||
shippingStateProvince, | ||
shippingPostalCode, | ||
shippingCountryCode, | ||
privateNotes, | ||
publicNotes, | ||
website, | ||
customValue1, | ||
customValue2, | ||
customValue3, | ||
customValue4, | ||
} = $.step.parameters; | ||
|
||
const bodyFields = { | ||
name: clientName, | ||
contacts: { | ||
first_name: contactFirstName, | ||
last_name: contactLastName, | ||
email: contactEmail, | ||
phone: contactPhone, | ||
}, | ||
settings: { | ||
language_id: languageCode, | ||
currency_id: currencyCode, | ||
}, | ||
id_number: idNumber, | ||
vat_number: vatNumber, | ||
address1: streetAddress, | ||
address2: aptSuite, | ||
city: city, | ||
state: stateProvince, | ||
postal_code: postalCode, | ||
country_id: countryCode, | ||
shipping_address1: shippingStreetAddress, | ||
shipping_address2: shippingAptSuite, | ||
shipping_city: shippingCity, | ||
shipping_state: shippingStateProvince, | ||
shipping_postal_code: shippingPostalCode, | ||
shipping_country_id: shippingCountryCode, | ||
private_notes: privateNotes, | ||
public_notes: publicNotes, | ||
website: website, | ||
custom_value1: customValue1, | ||
custom_value2: customValue2, | ||
custom_value3: customValue3, | ||
custom_value4: customValue4, | ||
}; | ||
|
||
const body = filterProvidedFields(bodyFields); | ||
|
||
const response = await $.http.post('/v1/clients', body); | ||
|
||
$.setActionItem({ raw: response.data.data }); | ||
}, | ||
}); |
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,3 @@ | ||
import createClient from './create-client'; | ||
|
||
export default [createClient]; |
18 changes: 18 additions & 0 deletions
18
packages/backend/src/apps/invoice-ninja/common/filter-provided-fields.ts
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,18 @@ | ||
import isObject from 'lodash/isObject'; | ||
|
||
export function filterProvidedFields(body: Record<string, unknown>) { | ||
return Object.keys(body).reduce<Record<string, unknown>>((result, key) => { | ||
const value = body[key]; | ||
if (isObject(value)) { | ||
const filteredNestedObj = filterProvidedFields( | ||
value as Record<string, unknown> | ||
); | ||
if (Object.keys(filteredNestedObj).length > 0) { | ||
result[key] = filteredNestedObj; | ||
} | ||
} else if (body[key]) { | ||
result[key] = value; | ||
} | ||
return result; | ||
}, {}); | ||
} |
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,12 @@ | ||
--- | ||
favicon: /favicons/invoice-ninja.svg | ||
items: | ||
- name: Create client | ||
desc: Creates a new client. | ||
--- | ||
|
||
<script setup> | ||
import CustomListing from '../../components/CustomListing.vue' | ||
</script> | ||
|
||
<CustomListing /> |