1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-19 13:29:41 +02:00
portainer/app/react/portainer/gitops/AuthFieldset/CredentialSelector.tsx
Chaim Lev-Ari b98c71f1ab
refactor(ui): move react components to react codebase [EE-3354] (#8258)
* refactor(ui): move react components to react codebase [EE-3354]

* refactor(app): move bocx selector options

* refactor(react): spearate portainer components

* fix(app): fix imports
2023-02-28 17:32:29 +02:00

48 lines
1.4 KiB
TypeScript

import { GitCredential } from '@/react/portainer/account/git-credentials/types';
import { useGitCredentials } from '@/react/portainer/account/git-credentials/git-credentials.service';
import { useUser } from '@/react/hooks/useUser';
import { FormControl } from '@@/form-components/FormControl';
import { Select } from '@@/form-components/ReactSelect';
export function CredentialSelector({
value,
onChange,
error,
}: {
value?: number;
onChange(gitCredential?: GitCredential | null): void;
error?: string;
}) {
const { user } = useUser();
const gitCredentialsQuery = useGitCredentials(user.Id);
const gitCredentials = gitCredentialsQuery.data ?? [];
return (
<div className="form-group">
<div className="col-sm-12">
<FormControl
label="Git Credentials"
inputId="git-creds-selector"
errors={error}
>
<Select
placeholder="select git credential or fill in below"
value={gitCredentials.find(
(gitCredential) => gitCredential.id === value
)}
options={gitCredentials}
getOptionLabel={(gitCredential) => gitCredential.name}
getOptionValue={(gitCredential) => gitCredential.id.toString()}
onChange={onChange}
isClearable
noOptionsMessage={() => 'no saved credentials'}
inputId="git-creds-selector"
/>
</FormControl>
</div>
</div>
);
}