Skip to content

Commit

Permalink
fix: project identifier cursor behaviour in create project modal. (#3320
Browse files Browse the repository at this point in the history
)
  • Loading branch information
prateekshourya29 authored and sriramveeraghanta committed Jan 22, 2024
1 parent 9eb8f41 commit 266f14d
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions web/components/project/create-project-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ export const CreateProjectModal: FC<Props> = observer((props) => {
else payload.emoji = formData.emoji_and_icon;

payload.project_lead = formData.project_lead_member;
// Upper case identifier
payload.identifier = payload.identifier.toUpperCase();

return createProject(workspaceSlug.toString(), payload)
.then((res) => {
Expand Down Expand Up @@ -176,22 +178,15 @@ export const CreateProjectModal: FC<Props> = observer((props) => {
return;
}
if (e.target.value === "") setValue("identifier", "");
else
setValue(
"identifier",
e.target.value
.replace(/[^ÇŞĞIİÖÜA-Za-z0-9]/g, "")
.toUpperCase()
.substring(0, 5)
);
else setValue("identifier", e.target.value.replace(/[^ÇŞĞIİÖÜA-Za-z0-9]/g, "").substring(0, 5));
onChange(e);
};

const handleIdentifierChange = (onChange: any) => (e: ChangeEvent<HTMLInputElement>) => {
const { value } = e.target;
const alphanumericValue = value.replace(/[^ÇŞĞIİÖÜA-Za-z0-9]/g, "");
setIsChangeInIdentifierRequired(false);
onChange(alphanumericValue.toUpperCase());
onChange(alphanumericValue);
};

return (
Expand Down Expand Up @@ -301,7 +296,8 @@ export const CreateProjectModal: FC<Props> = observer((props) => {
required: "Identifier is required",
// allow only alphanumeric & non-latin characters
validate: (value) =>
/^[ÇŞĞIİÖÜA-Z0-9]+$/.test(value.toUpperCase()) || "Identifier must be in uppercase.",
/^[ÇŞĞIİÖÜA-Z0-9]+$/.test(value.toUpperCase()) ||
"Only Alphanumeric & Non-latin characters are allowed.",
minLength: {
value: 1,
message: "Identifier must at least be of 1 character",
Expand All @@ -321,7 +317,7 @@ export const CreateProjectModal: FC<Props> = observer((props) => {
onChange={handleIdentifierChange(onChange)}
hasError={Boolean(errors.identifier)}
placeholder="Identifier"
className="w-full text-xs focus:border-blue-400"
className="w-full text-xs focus:border-blue-400 uppercase"
/>
)}
/>
Expand Down

0 comments on commit 266f14d

Please sign in to comment.