Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(create-modal): add value after creation input select value #1209

Merged
merged 7 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface ContainerRegistryCreateEditModalProps {
organizationId: string
isEdit?: boolean
registry?: ContainerRegistryResponse
onChange?: (e: string | string[]) => void
}

export const getOptionsContainerRegistry = (containerRegistry: AvailableContainerRegistryResponse[]) =>
Expand All @@ -41,6 +42,7 @@ export function ContainerRegistryCreateEditModal({
registry,
organizationId,
onClose,
onChange,
}: ContainerRegistryCreateEditModalProps) {
const methods = useForm<ContainerRegistryRequest>({
mode: 'onChange',
Expand Down Expand Up @@ -80,10 +82,12 @@ export function ContainerRegistryCreateEditModal({
})
onClose()
} else {
await createContainerRegistry({
const response = await createContainerRegistry({
organizationId: organizationId,
containerRegistryRequest,
})
// Update input select value with the new container registry id
onChange && onChange(response.id)
onClose()
}
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type GitAuthProvider, type GitTokenResponse } from 'qovery-typescript-axios'
import { Controller, useFormContext } from 'react-hook-form'
import { Controller, type ControllerRenderProps, type FieldValues, useFormContext } from 'react-hook-form'
import { useParams } from 'react-router-dom'
import { Icon, InputSelect, useModal } from '@qovery/shared/ui'
import { upperCaseFirstLetter } from '@qovery/shared/util-js'
Expand Down Expand Up @@ -49,6 +49,13 @@ export function GitProviderSetting({ disabled }: GitProviderSettingProps) {
]
: mergeProviders(authProviders, gitTokens)

const onChange = (field: ControllerRenderProps<FieldValues, 'provider'>, event: string | string[]) => {
field.onChange(event)
// Reset children fields
setValue('repository', undefined)
setValue('branch', undefined)
}

return (
<Controller
name="provider"
Expand All @@ -60,18 +67,19 @@ export function GitProviderSetting({ disabled }: GitProviderSettingProps) {
<InputSelect
label="Git repository"
options={providerOptions}
onChange={(event) => {
field.onChange(event)
// Reset children fields
setValue('repository', undefined)
setValue('branch', undefined)
}}
onChange={(event) => onChange(field, event)}
menuListButton={{
title: 'Select repository',
label: 'New git access',
onClick: () => {
openModal({
content: <GitTokenCreateEditModal organizationId={organizationId} onClose={closeModal} />,
content: (
<GitTokenCreateEditModal
organizationId={organizationId}
onClose={closeModal}
onChange={(event) => onChange(field, event)}
/>
),
})
},
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@ export interface GitTokenCreateEditModalProps {
organizationId: string
isEdit?: boolean
gitToken?: GitTokenResponse
onChange?: (e: string | string[]) => void
}

export function GitTokenCreateEditModal({ isEdit, gitToken, organizationId, onClose }: GitTokenCreateEditModalProps) {
export function GitTokenCreateEditModal({
isEdit,
gitToken,
organizationId,
onClose,
onChange,
}: GitTokenCreateEditModalProps) {
const methods = useForm({
mode: 'onChange',
defaultValues: {
Expand All @@ -37,10 +44,12 @@ export function GitTokenCreateEditModal({ isEdit, gitToken, organizationId, onCl
gitTokenRequest: data,
})
} else {
await createGitToken({
const response = await createGitToken({
organizationId,
gitTokenRequest: data,
})
// Update input select value with the new git token id
onChange && onChange(response.id)
}
onClose()
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useEditHelmRepository } from '../hooks/use-edit-helm-repository/use-edi
export interface HelmRepositoryCreateEditModalProps {
onClose: () => void
organizationId: string
onChange?: (e: string | string[]) => void
isEdit?: boolean
repository?: HelmRepositoryResponse
}
Expand All @@ -18,6 +19,7 @@ export function HelmRepositoryCreateEditModal({
repository,
organizationId,
onClose,
onChange,
}: HelmRepositoryCreateEditModalProps) {
const { data: availableHelmRepositories = [] } = useAvailableHelmRepositories()
const { mutateAsync: editHelmRepository, isLoading: isEditHelmRepositoryLoading } = useEditHelmRepository()
Expand Down Expand Up @@ -55,10 +57,12 @@ export function HelmRepositoryCreateEditModal({
helmRepositoryRequest,
})
} else {
await createHelmRepository({
const response = await createHelmRepository({
organizationId: organizationId,
helmRepositoryRequest,
})
// Update input select value with the new repository id
onChange && onChange(response.id)
}
onClose()
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ export function SourceSetting({ disabled = false }: { disabled?: boolean }) {
onClick: () => {
openModal({
content: (
<HelmRepositoryCreateEditModal organizationId={organizationId} onClose={closeModal} />
<HelmRepositoryCreateEditModal
organizationId={organizationId}
onClose={closeModal}
onChange={field.onChange}
/>
),
})
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ export function ClusterCredentialsSettingsFeature({ cloudProvider }: ClusterCred
cloudProvider,
})

const openCredentialsModal = (id?: string) => {
const openCredentialsModal = (id?: string, onChange?: (e: string | string[]) => void) => {
openModal({
content: (
<CreateEditCredentialsModalFeature
currentCredential={credentials.find((currentCredentials: ClusterCredentials) => currentCredentials.id === id)}
cloudProvider={cloudProvider!}
onClose={closeModal}
organizationId={organizationId}
onChange={onChange}
/>
),
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface CreateEditCredentialsModalFeatureProps {
cloudProvider: CloudProviderEnum
organizationId: string
currentCredential?: ClusterCredentials
onChange?: (e: string | string[]) => void
}

export const handleSubmit = (data: FieldValues, cloudProvider: CloudProviderEnum) => {
Expand Down Expand Up @@ -52,7 +53,7 @@ export const handleSubmit = (data: FieldValues, cloudProvider: CloudProviderEnum
}

export function CreateEditCredentialsModalFeature(props: CreateEditCredentialsModalFeatureProps) {
const { cloudProvider, onClose, currentCredential, organizationId } = props
const { cloudProvider, onClose, currentCredential, organizationId, onChange } = props
const [loading, setLoading] = useState(false)

const { enableAlertClickOutside } = useModal()
Expand Down Expand Up @@ -84,10 +85,12 @@ export function CreateEditCredentialsModalFeature(props: CreateEditCredentialsMo
})
onClose()
} else {
await createCloudProviderCredential({
const response = await createCloudProviderCredential({
organizationId,
...credentials,
})
// Update input select value with the new credential id
onChange && onChange(response.id)
onClose()
}
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Icon, InputSelect, LoaderSpinner } from '@qovery/shared/ui'

export interface ClusterCredentialsSettingsProps {
credentials?: ClusterCredentials[]
openCredentialsModal: (id?: string) => void
openCredentialsModal: (id?: string, onChange?: (e: string | string[]) => void) => void
loading: boolean
}

Expand Down Expand Up @@ -45,7 +45,7 @@ export function ClusterCredentialsSettings(props: ClusterCredentialsSettingsProp
title: 'Select credential',
label: 'New credential',
icon: <Icon iconName="circle-plus" className="text-brand-500" />,
onClick: () => openCredentialsModal(),
onClick: () => openCredentialsModal(undefined, field.onChange),
}}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ export function GeneralContainerSettings({ organization, className }: GeneralCon
onClick: () => {
openModal({
content: organization && (
<ContainerRegistryCreateEditModal organizationId={organization.id} onClose={closeModal} />
<ContainerRegistryCreateEditModal
organizationId={organization.id}
onClose={closeModal}
onChange={field.onChange}
/>
),
})
},
Expand Down
Loading