Skip to content

Commit

Permalink
feat: add defaultCurrency to company
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanvanherwijnen committed Aug 28, 2024
1 parent 6a76878 commit 302abfc
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export async function up(db: Kysely<unknown>): Promise<void> {
.addColumn('bic', 'varchar', (col) => col.notNull())
.addColumn('default_number_prefix_template', 'varchar')
.addColumn('default_locale', 'varchar')
.addColumn('default_currency', 'varchar')

.addColumn('created_at', 'text', (col) =>
col.defaultTo(sql`CURRENT_TIMESTAMP`).notNull()
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/kysely/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export interface Companies {
website?: string | null
defaultNumberPrefixTemplate?: string | null
defaultLocale?: string | null
defaultCurrency?: 'EUR' | 'USD' | null
createdAt: Generated<string>
}

Expand Down
3 changes: 2 additions & 1 deletion packages/api/src/repositories/company.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const defaultSelect = [
'prefix',
'website',
'defaultNumberPrefixTemplate',
'defaultLocale'
'defaultLocale',
'defaultCurrency'
] as (keyof Company)[]

function find({
Expand Down
12 changes: 8 additions & 4 deletions packages/api/src/trpc/admin/companies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export const adminCompanyRoutes = ({
website,
prefix,
defaultNumberPrefixTemplate,
defaultLocale
defaultLocale,
defaultCurrency
} = input

let logoSvg = input.logoSvg
Expand Down Expand Up @@ -69,7 +70,8 @@ export const adminCompanyRoutes = ({
prefix,
logoSvg,
defaultNumberPrefixTemplate,
defaultLocale
defaultLocale,
defaultCurrency
})
if (result) return result

Expand Down Expand Up @@ -117,7 +119,8 @@ export const adminCompanyRoutes = ({
website,
prefix,
defaultNumberPrefixTemplate,
defaultLocale
defaultLocale,
defaultCurrency
} = input

let logoSvg = input.logoSvg
Expand Down Expand Up @@ -151,7 +154,8 @@ export const adminCompanyRoutes = ({
prefix,
logoSvg,
defaultNumberPrefixTemplate,
defaultLocale
defaultLocale,
defaultCurrency
}
)
if (result) return result
Expand Down
6 changes: 5 additions & 1 deletion packages/api/src/zod/company.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ export const companyValidation = {
prefix: z.string(),
logoSvg: z.string().nullable().optional(),
defaultNumberPrefixTemplate: z.string().nullable().optional(),
defaultLocale: z.string().nullable().optional()
defaultLocale: z.string().nullable().optional(),
defaultCurrency: z
.union([z.literal('EUR'), z.literal('USD')])
.nullable()
.optional()
}

export const company = z.object(companyValidation)
Expand Down
20 changes: 16 additions & 4 deletions packages/app/src/components/company/CompanyForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,23 @@
:filtered-options="filteredNumberPrefixes"
bottom-slots
lazy-rules
name="defaultNumberPrefixTemplate"
/>
<locale-select
v-model="modelValue.defaultLocale"
:label="lang.company.fields.defaultLocale"
required
class="col-md-3 col-12"
bottom-slots
lazy-rules
name="locale"
name="defaultLocale"
/>
<currency-select
v-model="modelValue.defaultCurrency"
:label="lang.company.fields.defaultCurrency"
class="col-md-3 col-12"
bottom-slots
lazy-rules
name="defaultCurrency"
/>
</div>
</q-form>
Expand All @@ -183,7 +191,10 @@ import { type ResponsiveDialog } from '@simsustech/quasar-components'
import { FormInput } from '@simsustech/quasar-components/form'
import SvgAvatar from '../SvgAvatar.vue'
import NumberPrefixSelect from '../numberPrefix/NumberPrefixSelect.vue'
import { LocaleSelect } from '@simsustech/quasar-components/form'
import {
LocaleSelect,
CurrencySelect
} from '@simsustech/quasar-components/form'
import { Company, NumberPrefix } from '@slimfact/api/zod'
export interface Props {
form?: QFormProps & Partial<HTMLFormElement> & Partial<HTMLDivElement>
Expand Down Expand Up @@ -232,7 +243,8 @@ const initialValue: Company = {
prefix: '',
website: null,
defaultNumberPrefixTemplate: '',
defaultLocale: 'en-US'
defaultLocale: 'en-US',
defaultCurrency: 'EUR'
}
const modelValue = ref<Company>(initialValue)
Expand Down
6 changes: 5 additions & 1 deletion packages/app/src/components/invoice/InvoiceForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,11 @@ watch(
(company) => company.id === newVal
)?.defaultLocale
if (defaultLocale) modelValue.value.locale = defaultLocale
const defaultCurrency = filteredCompanies.value.find(
(company) => company.id === newVal
)?.defaultCurrency
if (defaultCurrency) modelValue.value.currency = defaultCurrency
}
)
Expand Down Expand Up @@ -366,7 +371,6 @@ const submitClient: InstanceType<
const updateClient: InstanceType<
typeof ClientForm
>['$props']['onSubmit'] = async ({ data, done }) => {
console.log(data)
modelValue.value.clientDetails = data
done()
Expand Down
5 changes: 5 additions & 0 deletions packages/app/src/components/subscription/SubscriptionForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,11 @@ watch(
(company) => company.id === newVal
)?.defaultLocale
if (defaultLocale) modelValue.value.locale = defaultLocale
const defaultCurrency = filteredCompanies.value.find(
(company) => company.id === newVal
)?.defaultCurrency
if (defaultCurrency) modelValue.value.currency = defaultCurrency
}
)
Expand Down
3 changes: 2 additions & 1 deletion packages/app/src/lang/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ const lang: Language = {
prefix: 'Prefix',
bic: 'BIC',
defaultNumberPrefixTemplate: 'Default number prefix',
defaultLocale: 'Default locale'
defaultLocale: 'Default locale',
defaultCurrency: 'Default currency'
},
validations: {
fieldRequired: 'Field is required'
Expand Down
1 change: 1 addition & 0 deletions packages/app/src/lang/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export interface Language {
bic: string
defaultNumberPrefixTemplate: string
defaultLocale: string
defaultCurrency: string
}
validations: {
fieldRequired: string
Expand Down
3 changes: 2 additions & 1 deletion packages/app/src/lang/nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ const lang: Language = {
website: 'Website',
bic: 'BIC',
defaultNumberPrefixTemplate: 'Standaard nummer voorvoegsel',
defaultLocale: 'Standaard regio'
defaultLocale: 'Standaard regio',
defaultCurrency: 'Standaard valuta'
},
validations: {
fieldRequired: 'Veld is vereist'
Expand Down

0 comments on commit 302abfc

Please sign in to comment.