Skip to content

Commit

Permalink
Merge pull request #40 from the-collab-lab/tc-el-normalize-item-names
Browse files Browse the repository at this point in the history
implement changes for normalizing item names
  • Loading branch information
eva-lng authored Sep 26, 2024
2 parents 13baf18 + acb7feb commit c062b84
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/components/AddItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ export function AddItem({ data, listPath }) {
});
const [messageItem, setMessageItem] = useState('');

const normalizeItemName = (name) => {
const lowercaseName = name.toLowerCase();
const normalizedName =
lowercaseName.charAt(0).toUpperCase() + lowercaseName.slice(1);
return normalizedName;
};

const handleNewItemChange = (e) => {
const { name, value } = e.target;
setFormNewItem((prevForm) => {
Expand Down Expand Up @@ -44,10 +51,12 @@ export function AddItem({ data, listPath }) {
}

await addItem(listPath, {
itemName: name,
itemName: normalizeItemName(name),
daysUntilNextPurchase: nextPurchase,
});
alert(`${name} has been successfully added to the list`);
alert(
`${normalizeItemName(name)} has been successfully added to the list`,
);
setFormNewItem({
name: '',
nextPurchase: 0,
Expand Down

0 comments on commit c062b84

Please sign in to comment.