Skip to content

Commit

Permalink
ensure required fields present and update translations
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklloyd committed Jun 14, 2024
1 parent 6df84e5 commit 12d45b6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
6 changes: 1 addition & 5 deletions src/components/AuthorizeButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,7 @@ const AuthorizeButton = ({ connection, onConnectionChange }: Props) => {
);
}

const buttonText =
typeof connection?.service_id === 'string' &&
connection?.service_id.length > 15
? t('Authorize')
: `${t('Authorize')} ${connection.name}`;
const buttonText = t('Authorize', { connectionName: connection.name });
return (
<Button
text={buttonText}
Expand Down
25 changes: 25 additions & 0 deletions src/components/ConnectionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,31 @@ const ConnectionForm = ({ connection, setCurrentView, settings }: Props) => {
initialValues,
enableReinitialize: true,
onSubmit: async (values) => {
// Check if all required fields have values
const allRequiredFieldsFilled = formFields.every((field) => {
const fieldValue = values[field.id];
if (field.required) {
if (field.type === 'multi-select' || field.type === 'select') {
// Assuming multi-select fields store an array of strings
return Array.isArray(fieldValue) && fieldValue.length > 0;
} else {
// Handle other types as non-array values
return fieldValue !== undefined && (fieldValue as unknown) !== '';
}
}
return true; // If not required, no need to check
});

if (!allRequiredFieldsFilled) {
setValidationState('idle');
addToast({
type: 'error',
title: t('Missing required fields'),
description: t('Please fill all required fields before submitting.'),
});
return;
}

if (connection.validation_support) {
setValidationState('validating');
const updatedConnection = await updateConnection({
Expand Down
10 changes: 5 additions & 5 deletions src/utils/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const resources = {
'Something went wrong': 'Something went wrong',
'The integration could not be authorized. Please make sure your settings are correct and try again.':
'The integration could not be authorized. Please make sure your settings are correct and try again.',
Authorize: 'Authorize',
Authorize: 'Authorize {{connectionName}}',
'Missing required fields': 'Missing required fields',
'Missing required field mappings.': 'Missing required field mappings.',
'Field Mapping': 'Field Mapping',
Expand Down Expand Up @@ -145,7 +145,7 @@ const resources = {
'Something went wrong': 'Er is iets misgegaan',
'The integration could not be authorized. Please make sure your settings are correct and try again.':
'De integratie kon niet worden geautoriseerd. Controleer of je instellingen correct zijn en probeer het opnieuw.',
Authorize: 'Autoriseren',
Authorize: '{{connectionName}} Autoriseren',
'Missing required fields': 'Ontbrekende verplichte velden',
'Missing required field mappings.':
'Ontbrekende verplichte veldmappings.',
Expand Down Expand Up @@ -229,7 +229,7 @@ const resources = {
'Something went wrong': 'Quelque chose a mal tourné',
'The integration could not be authorized. Please make sure your settings are correct and try again.':
"L'intégration n'a pas pu être autorisée. Veuillez vérifier que vos paramètres sont corrects et réessayez.",
Authorize: 'Autoriser',
Authorize: 'Autoriser {{connectionName}}',
'Missing required fields': 'Champs obligatoires manquants',
'Missing required field mappings.':
'Mappages de champs obligatoires manquants.',
Expand Down Expand Up @@ -312,7 +312,7 @@ const resources = {
'Something went wrong': 'Etwas ist schiefgelaufen',
'The integration could not be authorized. Please make sure your settings are correct and try again.':
'Die Integration konnte nicht autorisiert werden. Bitte stellen Sie sicher, dass Ihre Einstellungen korrekt sind und versuchen Sie es erneut.',
Authorize: 'Autorisieren',
Authorize: '{{connectionName}} Autorisieren',
'Missing required fields': 'Fehlende erforderliche Felder',
'Missing required field mappings.':
'Fehlende erforderliche Feldzuordnungen.',
Expand Down Expand Up @@ -395,7 +395,7 @@ const resources = {
'Something went wrong': 'Algo salió mal',
'The integration could not be authorized. Please make sure your settings are correct and try again.':
'La integración no pudo ser autorizada. Por favor, asegúrate de que tus ajustes son correctos y vuelve a intentarlo.',
Authorize: 'Autorizar',
Authorize: 'Autorizar {{connectionName}}',
'Missing required fields': 'Faltan campos requeridos',
'Missing required field mappings.': 'Faltan mapeos de campos requeridos.',
'Field Mapping': 'Mapeo de Campo',
Expand Down
4 changes: 2 additions & 2 deletions stories/Vault.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const Template: Story<Props> = (args) => (
trigger={<button className="p-2 border rounded shadow">Open modal</button>}
{...args}
showConsumer={true}
unifyBaseUrl="http://localhost:3050"
token="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyZWRpcmVjdF91cmkiOiJodHRwczovL215c2Fhcy5jb20vZGFzaGJvYXJkIiwiY29uc3VtZXJfbWV0YWRhdGEiOnsiYWNjb3VudF9uYW1lIjoiU3BhY2VYIiwidXNlcl9uYW1lIjoiRWxvbiBNdXNrIiwiZW1haWwiOiJlbG9uQG11c2suY29tIiwiaW1hZ2UiOiJodHRwczovL3d3dy5zcGFjZXguY29tL3N0YXRpYy9pbWFnZXMvc2hhcmUuanBnIn0sImN1c3RvbV9jb25zdW1lcl9zZXR0aW5ncyI6eyJmZWF0dXJlX2ZsYWdfMSI6dHJ1ZSwidGF4X3JhdGVzIjpbeyJpZCI6IjYiLCJsYWJlbCI6IjYlIn0seyJpZCI6IjIxIiwibGFiZWwiOiIyMSUifV19LCJ0aGVtZSI6eyJmYXZpY29uIjoiaHR0cHM6Ly9yZXMuY2xvdWRpbmFyeS5jb20vcG9zdG1hbi9pbWFnZS91cGxvYWQvdF90ZWFtX2xvZ28vdjE2Mjk4ODY5NTgvdGVhbS9lM2JkN2RhZTRiODQ0MTliOWVjMGQzNGQ4NTVlMTE4MTZlOTRhY2QxYWY4OTRiMjNkYTQ0ZTkyNzA4ZTAzYTgxIiwicHJpbWFyeV9jb2xvciI6IiMyODZlZmEiLCJwcml2YWN5X3VybCI6Imh0dHBzOi8vY29tcGxpYW5jZS5hcGlkZWNrLmNvbS9wcml2YWN5LXBvbGljeSIsInNpZGVwYW5lbF9iYWNrZ3JvdW5kX2NvbG9yIjoiIzI4NmVmYSIsInNpZGVwYW5lbF90ZXh0X2NvbG9yIjoiI0ZGRkZGRiIsInRlcm1zX3VybCI6Imh0dHBzOi8vd3d3LnRlcm1zZmVlZC5jb20vdGVybXMtY29uZGl0aW9ucy85NTdjODVjMWIwODlhZTllMzI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