Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feature/midaz-logg…
Browse files Browse the repository at this point in the history
…er-v1
  • Loading branch information
Paulo Barbosa authored and Paulo Barbosa committed Jan 15, 2025
2 parents c23a36d + 987f31c commit 989f186
Show file tree
Hide file tree
Showing 12 changed files with 307 additions and 27 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# [1.2.0](https://github.com/LerianStudio/midaz-console/compare/v1.1.4...v1.2.0) (2025-01-15)


### Features

* set the paths of asset ([4f180c6](https://github.com/LerianStudio/midaz-console/commit/4f180c640a69969295a351a9654507f976f034ae))

## [1.1.4](https://github.com/LerianStudio/midaz-console/compare/v1.1.3...v1.1.4) (2024-12-23)

## [1.1.3](https://github.com/LerianStudio/midaz-console/compare/v1.1.2...v1.1.3) (2024-12-18)
Expand Down
8 changes: 4 additions & 4 deletions release.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ module.exports = {
{
preset: "conventionalcommits",
releaseRules: [
{ type: "chore", release: "patch" } // Included "chore" on patch type
{ type: "chore", release: "patch" }, // Included "chore" on patch type
{ type: "fix", release: "patch" } // Included "fix" on patch type
]
}
],
Expand All @@ -19,8 +20,7 @@ module.exports = {
"@semantic-release/github",
{
assets: [
{ path: ".next/static/chunks/*.js", label: "JavaScript distribution" },
{ path: ".next/static/chunks/*.js.map", label: "Source map" }
{ path: ".next/**", label: "Next.js build files" } // Updated to include all files in .next/
]
}
],
Expand All @@ -32,4 +32,4 @@ module.exports = {
}
]
]
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const BasicInformationPaper = ({
defaultMessage: 'Optional'
})}
control={control}
rows={1}
maxHeight={100}
textArea
/>
<InputField
Expand Down
13 changes: 8 additions & 5 deletions src/components/form/input-field/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AutosizeTextarea } from '@/components/ui/autosize-textarea'
import {
FormControl,
FormDescription,
Expand All @@ -8,7 +9,6 @@ import {
FormTooltip
} from '@/components/ui/form'
import { Input } from '@/components/ui/input'
import { Textarea } from '@/components/ui/textarea'
import { HTMLInputTypeAttribute, ReactNode } from 'react'
import { Control } from 'react-hook-form'

Expand All @@ -23,7 +23,8 @@ export type InputFieldProps = {
control: Control<any>
disabled?: boolean
readOnly?: boolean
rows?: number
minHeight?: number
maxHeight?: number
textArea?: boolean
required?: boolean
}
Expand All @@ -37,7 +38,8 @@ export const InputField = ({
description,
required,
readOnly,
rows,
minHeight,
maxHeight,
textArea,
...others
}: InputFieldProps) => {
Expand All @@ -57,10 +59,11 @@ export const InputField = ({
)}
<FormControl>
{textArea ? (
<Textarea
<AutosizeTextarea
placeholder={placeholder}
readOnly={readOnly}
rows={rows}
minHeight={minHeight}
maxHeight={maxHeight}
{...field}
/>
) : (
Expand Down
19 changes: 19 additions & 0 deletions src/components/ui/autosize-textarea/autosize-textarea.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Meta, Controls, Primary, Canvas } from '@storybook/blocks'
import * as Story from './autosize-textarea.stories'

<Meta of={Story} />

# Auto Size Textarea

Auto resize textarea height based on content. \
[Docs](https://shadcnui-expansions.typeart.cc/docs/autosize-textarea)

### Default

<Canvas of={Story.Default} />

### With Max Height

<Canvas of={Story.MaxHeight} />

<Controls />
50 changes: 50 additions & 0 deletions src/components/ui/autosize-textarea/autosize-textarea.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { ComponentProps } from 'react'
import { Meta, StoryObj } from '@storybook/react'
import { AutosizeTextarea, AutosizeTextAreaProps } from '.'
import { FormProvider, useForm } from 'react-hook-form'

const meta: Meta<AutosizeTextAreaProps> = {
title: 'Primitives/AutosizeTextarea',
component: AutosizeTextarea,
argTypes: {
disabled: {
type: 'boolean',
description: 'If the input is disabled'
},
className: {
type: 'string',
description: "The input's class"
}
}
}

export default meta

export const Default: StoryObj<AutosizeTextAreaProps> = {
args: {
placeholder: 'This textarea with min height 52 and unlimited max height.'
},
render: (args) => {
const form = useForm()
return (
<FormProvider {...form}>
<AutosizeTextarea {...args} />
</FormProvider>
)
}
}

export const MaxHeight: StoryObj<AutosizeTextAreaProps> = {
args: {
placeholder: 'This textarea with min height 52 and max height 200.',
maxHeight: 200
},
render: (args) => {
const form = useForm()
return (
<FormProvider {...form}>
<AutosizeTextarea {...args} />
</FormProvider>
)
}
}
112 changes: 112 additions & 0 deletions src/components/ui/autosize-textarea/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
'use client'

import * as React from 'react'
import { cn } from '@/lib/utils'
import { useImperativeHandle } from 'react'

interface UseAutosizeTextAreaProps {
textAreaRef: React.MutableRefObject<HTMLTextAreaElement | null>
minHeight?: number
maxHeight?: number
triggerAutoSize: string
}

export const useAutosizeTextArea = ({
textAreaRef,
triggerAutoSize,
maxHeight = Number.MAX_SAFE_INTEGER,
minHeight = 0
}: UseAutosizeTextAreaProps) => {
const [init, setInit] = React.useState(true)
React.useEffect(() => {
// We need to reset the height momentarily to get the correct scrollHeight for the textarea
const textAreaElement = textAreaRef.current
if (textAreaElement) {
if (init) {
textAreaElement.style.minHeight = `${minHeight}px`
if (maxHeight > minHeight) {
textAreaElement.style.maxHeight = `${maxHeight}px`
}
setInit(false)
}
textAreaElement.style.height = `${minHeight}px`
const scrollHeight = textAreaElement.scrollHeight

// We then set the height directly, outside of the render loop
// Trying to set this with state or a ref will product an incorrect value.
if (scrollHeight > maxHeight) {
textAreaElement.style.height = `${maxHeight}px`
textAreaElement.style.overflowY = 'auto'
} else {
textAreaElement.style.height = `${scrollHeight}px`
textAreaElement.style.overflowY = 'hidden'
}
}
}, [textAreaRef.current, triggerAutoSize])
}

export type AutosizeTextAreaRef = {
textArea: HTMLTextAreaElement
maxHeight: number
minHeight: number
}

export type AutosizeTextAreaProps = {
maxHeight?: number
minHeight?: number
} & React.TextareaHTMLAttributes<HTMLTextAreaElement>

export const AutosizeTextarea = React.forwardRef<
AutosizeTextAreaRef,
AutosizeTextAreaProps
>(
(
{
maxHeight = Number.MAX_SAFE_INTEGER,
minHeight = 36,
className,
onChange,
value,
...props
}: AutosizeTextAreaProps,
ref: React.Ref<AutosizeTextAreaRef>
) => {
const textAreaRef = React.useRef<HTMLTextAreaElement | null>(null)
const [triggerAutoSize, setTriggerAutoSize] = React.useState('')

useAutosizeTextArea({
textAreaRef,
triggerAutoSize: triggerAutoSize,
maxHeight,
minHeight
})

useImperativeHandle(ref, () => ({
textArea: textAreaRef.current as HTMLTextAreaElement,
focus: () => textAreaRef?.current?.focus(),
maxHeight,
minHeight
}))

React.useEffect(() => {
setTriggerAutoSize(value as string)
}, [props?.defaultValue, value])

return (
<textarea
{...props}
value={value}
ref={textAreaRef}
className={cn(
'flex h-9 w-full overflow-y-hidden rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50',
className
)}
onChange={(e) => {
setTriggerAutoSize(e.target.value)
onChange?.(e)
}}
/>
)
}
)
AutosizeTextarea.displayName = 'AutosizeTextarea'
7 changes: 5 additions & 2 deletions src/context/organization-provider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
FetchAllOrganizationsUseCase
} from '@/core/application/use-cases/organizations/fetch-all-organizations-use-case'
import { OrganizationProviderClient } from './organization-provider-client'
import { serverFetcher } from '@/lib/fetcher'

const fetchAllOrganizationsUseCase = container.get<FetchAllOrganizations>(
FetchAllOrganizationsUseCase
Expand All @@ -19,10 +20,12 @@ export const OrganizationProvider = async ({
* TODO: Call the proper get organizations for user
* For now we setting the first organization as the current one
*/
const result = await fetchAllOrganizationsUseCase.execute(10, 1)
const result = await serverFetcher(
async () => await fetchAllOrganizationsUseCase.execute(10, 1)
)

return (
<OrganizationProviderClient organization={result.items[0]}>
<OrganizationProviderClient organization={result?.items[0]!}>
{children}
</OrganizationProviderClient>
)
Expand Down
7 changes: 4 additions & 3 deletions src/context/permission-provider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { container } from '@/core/infrastructure/container-registry/container-re
import { nextAuthCasdoorOptions } from '@/core/infrastructure/next-auth/casdoor/next-auth-casdoor-provider'
import { getServerSession } from 'next-auth'
import { PermissionProviderClient } from './permission-provider-client'
import { serverFetcher } from '@/lib/fetcher'

const authPermissionUseCase = container.get<AuthPermission>(
AuthPermissionUseCase
Expand All @@ -18,12 +19,12 @@ export const PermissionProvider = async ({
}: React.PropsWithChildren) => {
const session = await getServerSession(nextAuthCasdoorOptions)

const permissions = await authPermissionUseCase.execute(
session?.user.username
const permissions = await serverFetcher(
async () => await authPermissionUseCase.execute(session?.user.username)
)

return (
<PermissionProviderClient permissions={permissions}>
<PermissionProviderClient permissions={permissions!}>
{children}
</PermissionProviderClient>
)
Expand Down
Loading

0 comments on commit 989f186

Please sign in to comment.