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

Add new input preferred_client_id to ClientCreateContainer #7

Merged
merged 7 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Release Candidate

### Refactoring

- Add new input `preferred_client_id` to ClientCreateContainer (INDIGO Sprint 221209, [!7](https://github.com/TeskaLabs/seacat-admin-webui/pull/7))

## v22.48

### Compatibility
Expand Down
2 changes: 2 additions & 0 deletions public/locales/cs/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"Create new client": "Vytvořit nového klienta",
"Template": "Šablona",
"Client name": "Název klienta",
"Preferred client ID": "Preferované ID klienta",
"Client URI": "URI klienta",
"Response types": "Typy odpovědí",
"Grant types": "Typy grantů",
Expand Down Expand Up @@ -133,6 +134,7 @@
"ClientFormField": {
"Add new input": "Přidat pole",
"Remove input": "Odstranit pole",
"Invalid format, input should have minimum of 8 characters": "Nesprávný formát, pole musí mít minimálně 8 znaků",
"URI can't be empty": "URI nemůže být prázdný",
"URI have to start with https": "URI musí začínat https",
"URL hash have to be empty": "URL hash musí být prázdný",
Expand Down
2 changes: 2 additions & 0 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"Create new client": "Create new client",
"Template": "Template",
"Client name": "Client name",
"Preferred client ID": "Preferred client ID",
"Client URI": "Client URI",
"Response types": "Response types",
"Grant types": "Grant types",
Expand Down Expand Up @@ -133,6 +134,7 @@
"ClientFormField": {
"Add new input": "Add new input",
"Remove input": "Remove input",
"Invalid format, input should have minimum of 8 characters": "Invalid format, input should have minimum of 8 characters",
"URI can't be empty": "URI can't be empty",
"URI have to start with https": "URI have to start with https",
"URL hash have to be empty": "URL hash have to be empty",
Expand Down
6 changes: 6 additions & 0 deletions src/modules/auth/clients/ClientCreateContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ const ClientCreateContainer = (props) => {
body.client_name = "";
}

if (body.preferred_client_id == "" || body.preferred_client_id == undefined) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Aringoaway wrap conditions ((body.preferred_client_id == "") || (body.preferred_client_id == undefined))

delete body.preferred_client_id;
}

try {
let response = await SeaCatAuthAPI.post(`/client`, body);
if (response.statusText != 'OK') {
Expand Down Expand Up @@ -143,6 +147,7 @@ const ClientCreateContainer = (props) => {
const changeTemplate = (value) => {
resetField("client_name");
resetField("client_uri");
resetField("preferred_client_id");
resetField("application_type");
resetField("grant_types");
resetField("response_types");
Expand Down Expand Up @@ -185,6 +190,7 @@ const ClientCreateContainer = (props) => {
case 'redirect_uris': return(<URiInput key={key} name={key} control={control} errors={errors} append={append} remove={remove} fields={fields} labelName={t("ClientCreateContainer|Redirect URIs")}/>)
case 'client_name': return(<TextInput key={key} name={key} register={register} labelName={t('ClientCreateContainer|Client name')}/>)
case 'client_uri': return(<TextInput key={key} name={key} register={register} labelName={t('ClientCreateContainer|Client URI')}/>)
case 'preferred_client_id': return(<TextInput key={key} name={key} register={register} errors={errors} labelName={t('ClientCreateContainer|Preferred client ID')}/>)
case 'response_types': return(selectedTemplate === "Custom" && <MultiCheckbox key={key} name={key} value={value["items"]["enum"]} setValue={setValue} labelName={t('ClientCreateContainer|Response types')}/>)
case 'grant_types': return(selectedTemplate === "Custom" && <MultiCheckbox key={key} name={key} value={value["items"]["enum"]} setValue={setValue} labelName={t('ClientCreateContainer|Grant types')}/>)
case 'application_type': return(selectedTemplate === "Custom" && <SelectInput key={key} name={key} register={register} value={value["enum"]} labelName={t('ClientCreateContainer|Application type')}/>)
Expand Down
17 changes: 13 additions & 4 deletions src/modules/auth/clients/FormFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@ import { useTranslation } from 'react-i18next';
import { Controller } from "react-hook-form";

// The usual text input
export function TextInput ({ name, register, labelName, disabled }) {
export function TextInput ({ name, register, errors, labelName, disabled }) {
const { t } = useTranslation();
const reg = register(name);
const reg = register(
name,
(name == "preferred_client_id") && {
validate: {
validation: value => (/^[-_a-zA-Z0-9]{8,64}$|^$/).test(value) || t("ClientFormField|Invalid format, input should have minimum of 8 characters"),
}
}
);
return (
<FormGroup key={name}>
{labelName && <Label for={name}>{labelName}</Label>}
Expand All @@ -18,11 +25,13 @@ export function TextInput ({ name, register, labelName, disabled }) {
name={name}
type="text"
disabled={disabled}
required={name == "client_name" ? true : false}
onChange={reg.onChange}
onBlur={reg.onBlur}
innerRef={reg.ref}

invalid={errors?.preferred_client_id && errors.preferred_client_id}
/>
{errors?.preferred_client_id && <FormFeedback>{errors.preferred_client_id.message}</FormFeedback>}
</FormGroup>
)
}
Expand Down Expand Up @@ -65,7 +74,7 @@ export function URiInput ({ name, control, errors, append, remove, fields, label
return (
<InputGroup key={item.id} className="mb-1">
<Controller
render={({field}) => <Input {...field} invalid={errors.redirect_uris?.[idx]?.text} disabled={disabled}/>}
render={({field}) => <Input {...field} required={true} invalid={errors.redirect_uris?.[idx]?.text} disabled={disabled}/>}
name={`redirect_uris[${idx}].text`}
control={control}
rules={{
Expand Down