-
Notifications
You must be signed in to change notification settings - Fork 0
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
Muokkaus-näppäin json-serveriin #9
Merged
Merged
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
5b51882
Created a new component called ModifyModal.tsx. Changed variables nam…
2976804
Fixed typos in jsonServerFunctions.ts
917f156
Changed jsonServerFunctions way to be imported
0525e76
Changed jsonServerFunctions way to be imported and added onClick func…
dfbc58d
Added a new prop for className attribute in Modal.tsx
c644162
Added styling into edit modal
21d5d1b
Changed variables, functions and file names from Modifying to Edit fo…
99a67bb
Changed the way code checks if found a gift to be deleted. GET reques…
134b6d5
Changed the way how Update function in jsonServerFunctions.ts finds t…
86d0ef4
Changed the positions of gift inputs in index.tsx to make gift's rece…
75212d4
Editing a gift works now. Deleted some debug console.logs and backup …
dfe2d07
Added a form to EditModal.tsx to make enter key able to submit the ed…
4014341
Changed the positions of gift inputs in EditModal.tsx to make gift's …
d80a02b
ESLint fixes
042992d
Merged antti/json-server branch into antti/json-server-edit-button
anttiasmala 3276edf
Changed giftListRefreshFunction -> refreshGiftList to have a same nam…
anttiasmala 3edef50
Deleted remains of the merge. Fixed refreshGiftList function prop names
anttiasmala b12d516
Added curly braces into else statement. Changed backgroundClassName -…
anttiasmala 5188a1f
Changed backgroundClassName -> circleClassName
anttiasmala cb4686f
Fixed all the imports. Changed EditModal_Type to EditModal. Changed g…
anttiasmala 9dc8f03
Created a new file moveInputCursorToEnd.ts. Created a function that m…
anttiasmala 1f3a2e6
Added moveInputCursorToEnd function into onClick prop to make input's…
anttiasmala 1fbe6f2
Changed cleanFunctions -> clearFunctions in index.tsx. ESLint fixes
anttiasmala 2bf644c
Deleted moveInputCursorToEnd. Didn't work as well as though first
anttiasmala 917be40
Changed Put-method with Patch-method. Changed newObject to have Parti…
anttiasmala e8b2cc3
Added a try/catch block. Added checks for an Axios error as well as f…
anttiasmala 2db971d
Deleted useEffect that was not required. When closing modal by pressi…
anttiasmala 0cc2f8e
Deleted console.log that was used for debugging and testing purposes
anttiasmala File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import { | ||
Dispatch, | ||
FormEvent, | ||
SetStateAction, | ||
useEffect, | ||
useState, | ||
} from 'react'; | ||
import { Gift } from '~/pages'; | ||
import { Modal } from './Modal'; | ||
import { TitleText } from './TitleText'; | ||
import { Button } from './Button'; | ||
import { updateGift } from '~/utils/jsonServerFunctions'; | ||
import { Input } from './Input'; | ||
import { SvgCheckMarkIcon } from '~/icons/CheckMarkIcon'; | ||
import { SvgDeclineIcon } from '~/icons/DeclineIcon'; | ||
import { isAxiosError } from 'axios'; | ||
|
||
type EditModal = { | ||
gift: Gift; | ||
refreshGiftList: () => void; | ||
setIsModalOpen: Dispatch<SetStateAction<boolean>>; | ||
}; | ||
|
||
export function EditModal({ | ||
gift, | ||
refreshGiftList, | ||
setIsModalOpen, | ||
}: EditModal) { | ||
const [giftReceiver, setGiftReceiver] = useState(gift.name); | ||
const [giftName, setGiftName] = useState(gift.gift); | ||
|
||
useEffect(() => { | ||
function handleKeyDown(e: KeyboardEvent) { | ||
if (e.key === 'Escape') { | ||
setIsModalOpen(false); | ||
} | ||
} | ||
document.addEventListener('keydown', handleKeyDown); | ||
return function clearFunctions() { | ||
document.removeEventListener('keydown', handleKeyDown); | ||
}; | ||
}, [refreshGiftList, setIsModalOpen]); | ||
|
||
async function handleEdit(e: FormEvent<HTMLElement>) { | ||
e.preventDefault(); | ||
try { | ||
await updateGift(gift.id, { name: giftReceiver, gift: giftName }); | ||
} catch (e) { | ||
if (isAxiosError(e) && e.response?.status === 404) { | ||
console.error('Lahjaa ei löytynyt palvelimelta!'); | ||
} else if (e instanceof Error) { | ||
console.error(e.message); | ||
} else { | ||
console.error(e); | ||
} | ||
} | ||
refreshGiftList(); | ||
setIsModalOpen(false); | ||
} | ||
return ( | ||
<Modal className="sm:w-[26rem]"> | ||
<form onSubmit={(e) => void handleEdit(e)}> | ||
<TitleText className="row-start-1 row-end-1 ps-3 font-bold text-lg"> | ||
Muokkaus | ||
</TitleText> | ||
<div className="row-start-2 row-end-2 grid mt-1 pt-3"> | ||
<label className="row-start-1 row-end-1">Saaja</label> | ||
<Input | ||
className="row-start-2 row-end-2 ps-3 pt-5 text-lg w-full h-full font-bold" | ||
onChange={(e) => setGiftReceiver(e.target.value)} | ||
value={giftReceiver} | ||
autoComplete="off" | ||
/> | ||
</div> | ||
<div className="row-start-3 row-end-3 grid pt-3"> | ||
<label className="row-start-1 row-end-1">Lahja</label> | ||
<Input | ||
className="row-start-2 row-end-2 ps-3 pt-5 text-lg w-full h-full font-bold border" | ||
onChange={(e) => setGiftName(e.target.value)} | ||
value={giftName} | ||
name="giftName" | ||
autoComplete="off" | ||
/> | ||
</div> | ||
<div className="row-start-4 row-end-4 grid"> | ||
<Button | ||
className="relative mt-2 left-24 border border-yellow-500 p-0 row-start-1 row-end-1 col-start-1 col-end-1 w-[66px] h-[66px] " | ||
type="submit" | ||
> | ||
<SvgCheckMarkIcon | ||
width={64} | ||
height={64} | ||
className="bg-gray-300 hover:bg-gray-600 group/checkMarkIcon" | ||
circleClassName="fill-black group-hover/checkMarkIcon:fill-yellow-400 " | ||
checkMarkClassName="fill-gray-300 group-hover/checkMarkIcon:fill-gray-600" | ||
/> | ||
</Button> | ||
|
||
<Button | ||
className="mt-2 border border-yellow-500 relative p-0 row-start-1 row-end-1 col-start-2 col-end-2 w-[66px] h-[66px]" | ||
type="button" | ||
> | ||
<SvgDeclineIcon | ||
className="bg-gray-300 hover:bg-gray-600 group/declineIcon" | ||
circleClassName="fill-black group-hover/declineIcon:fill-yellow-400" | ||
width={64} | ||
height={64} | ||
onClick={() => setIsModalOpen(false)} | ||
/> | ||
</Button> | ||
</div> | ||
</form> | ||
</Modal> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tämä console.log on mielestäni tarpeeton, kun alla lokitetaan joka tapauksessa.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oli näköjään testi console.log jäänyt siihen 😅