Skip to content

Commit

Permalink
feat: ANT-2534 - Create project v2
Browse files Browse the repository at this point in the history
  • Loading branch information
marlenetienne authored and vargastat committed Feb 3, 2025
1 parent e542a4d commit 7b63d07
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 33 deletions.
23 changes: 12 additions & 11 deletions src/components/common/modal/ProjectCreationModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const ProjectCreationModal = ({ onClose }: ProjectCreationModalProps) =>
<RdsModal size="small">
<RdsModal.Title onClose={onClose}>{t('home.@new_project')}</RdsModal.Title>
<RdsModal.Content>
<div className="flex w-7/12 flex-col items-start gap-4">
<div className="flex w-8/12 flex-col items-start gap-2">
<RdsInputText
label="Name"
value={name}
Expand All @@ -88,22 +88,23 @@ export const ProjectCreationModal = ({ onClose }: ProjectCreationModalProps) =>
maxLength={40}
autoFocus={true}
/>
<RdsInputTextArea
label="Description"
value={description}
onChange={(t) => {
if (t.length <= 500) setDescription(t || '');
}}
maxLength={500}
placeHolder="Add a few lines to describe your project..."
/>
<div className="flex w-full [&_textarea]:min-h-[300px] [&_textarea]:resize-none">
<RdsInputTextArea
label="Description"
value={description}
onChange={(t) => {
if (t.length <= 500) setDescription(t || '');
}}
maxLength={500}
placeHolder="Add a few lines to describe your project..."
/>
</div>
<KeywordsInput
keywords={keywords}
setKeywords={setKeywords}
maxNbKeywords={6}
maxNbCharacters={15}
minNbCharacters={3}
width={'w-3/4'}
/>
</div>
</RdsModal.Content>
Expand Down
38 changes: 29 additions & 9 deletions src/pages/pegase/studies/KeywordsInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ const KeywordsInput: React.FC<KeywordsInputProps> = ({
const [suggestedKeywords, setSuggestedKeywords] = useState<string[]>([]);

const handleKeywordChange = async (value: string) => {
if (value.length > maxNbCharacters) {
return;
}
setKeywordInput(value);
setErrorMessage(''); // Clear error message when input changes
try {
Expand Down Expand Up @@ -69,24 +72,41 @@ const KeywordsInput: React.FC<KeywordsInputProps> = ({

const clearAllKeywords = () => {
setKeywords([]);
setErrorMessage('');
setKeywordInput('');
};

const handleRemoveKeyword = (index: number) => {
setKeywords((prevKeywords) => prevKeywords.filter((_, i) => i !== index));
};

const shouldAddKeywordButton = (input: string): boolean => {
if (!input) {
return false;
} else {
if (minNbCharacters) {
return input.length >= minNbCharacters;
} else if (minNbCharacters && maxNbCharacters) {
return input.length >= minNbCharacters && input.length <= maxNbCharacters;
}
}
};

return (
<div className={clsx(width ?? 'w-full', 'flex min-h-18 flex-col items-start justify-start')}>
<div className="relative flex w-full">
<div className="flex w-full items-center gap-4">
<RdsInputText
label="Keywords"
value={keywordInput}
onChange={handleKeywordChange}
placeHolder="Add a keyword"
variant="outlined"
/>
{keywordInput && (minNbCharacters ? keywordInput.length >= minNbCharacters : true) && (
<div className="flex w-full items-center gap-2">
<div className="max-w-3/4 flex">
<RdsInputText
label="Keywords"
value={keywordInput}
onChange={handleKeywordChange}
placeHolder="Add a keyword"
variant="outlined"
maxLength={maxNbCharacters ?? null}
/>
</div>
{shouldAddKeywordButton(keywordInput) && (
<RdsButton
onClick={() => handleAddKeyword()}
icon={RdsIconId.Add}
Expand Down
7 changes: 1 addition & 6 deletions src/shared/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@
"@keyword_length_error": "Keyword must be between {{min}} and {{max}} characters",
"@keyword_minimum_error": "Keyword must be at least {{min}} characters",
"@keyword_maximum_error": "Keyword must not exceed {{max}} characters",
"@keyword_max_keys_errors": "Cannot add more than ${maxNbKey} keywords`"
},
"study": {
"@open": "Open",
"@duplicate": "Duplicate",
"@delete": "Delete"
"@keyword_max_keys_errors": "Cannot add more than {{maxNbKey}} keywords"
}
}
9 changes: 2 additions & 7 deletions src/shared/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,8 @@
"projectModal": {
"@keyword_already_exists": "Le mot-clé existe déjà",
"@keyword_length_error": "Le mot-clé doit avoir entre {{min}} et {{max}} lettres",
"@keyword_minimum_error": "Le mot-clé doit avoir à minumum {{min}} lettres",
"@keyword_minimum_error": "Le mot-clé doit avoir à minimum {{min}} lettres",
"@keyword_maximum_error": "Le mot-clé ne doit pas dépasser {{max}} lettres",
"@keyword_max_keys_errors": "Il n'est pas possible d'ajouter plus que ${maxNbKey} mot-clés`"
},
"study": {
"@open": "Ouvrir",
"@duplicate": "Dupliquer",
"@delete": "Effacer"
"@keyword_max_keys_errors": "Il n'est pas possible d'ajouter plus que {{maxNbKey}} mot-clés"
}
}

0 comments on commit 7b63d07

Please sign in to comment.