-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: create types and schemas for the link edit * feat: functions for the editing of the link with the id * chore: create the visual for the editing of the linsk * chore: format code
- Loading branch information
1 parent
095ce08
commit bd41465
Showing
10 changed files
with
230 additions
and
24 deletions.
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,80 @@ | ||
import { TextField } from '@/components/text-field'; | ||
import { Button } from '@/components/ui/button'; | ||
import { | ||
Dialog, | ||
DialogContent, | ||
DialogDescription, | ||
DialogFooter, | ||
DialogHeader, | ||
DialogTitle, | ||
DialogTrigger, | ||
} from '@/components/ui/dialog'; | ||
import { DropdownMenuItem } from '@/components/ui/dropdown-menu'; | ||
import useLinks from '@/hooks/useLinks'; | ||
import { toFormikValidationSchema } from '@/utils/toFormikValidationSchema'; | ||
import { type ILink, LinkForUpdateSchema } from '@linx/shared'; | ||
import { Link1Icon } from '@radix-ui/react-icons'; | ||
import { useFormik } from 'formik'; | ||
import { useState } from 'react'; | ||
|
||
export function LinkDialogEdit({ | ||
link, | ||
setIsOpen, | ||
}: { link: ILink; setIsOpen: (isOpen: boolean) => void }) { | ||
const { update } = useLinks(); | ||
const { values, errors, handleChange, handleSubmit } = useFormik({ | ||
initialValues: { | ||
url: link.url, | ||
shorter_name: link.shorter_name, | ||
id: link.id, | ||
}, | ||
validationSchema: toFormikValidationSchema(LinkForUpdateSchema), | ||
validateOnChange: false, | ||
validateOnBlur: false, | ||
onSubmit: async (values) => { | ||
const dto = LinkForUpdateSchema.parse(values); | ||
|
||
update(dto); | ||
setIsOpen(false); | ||
}, | ||
}); | ||
return ( | ||
<DialogContent className="sm:max-w-[425px]"> | ||
<DialogHeader> | ||
<DialogTitle>Edit link</DialogTitle> | ||
</DialogHeader> | ||
<div> | ||
<form id="edit-link" className="space-y-4" onSubmit={handleSubmit}> | ||
<TextField | ||
label="Shorter Name" | ||
type="text" | ||
id="shorter_name" | ||
name="shorter_name" | ||
placeholder="linx-short-url" | ||
autoComplete="off" | ||
value={values.shorter_name} | ||
error={errors.shorter_name} | ||
onChange={handleChange} | ||
required | ||
/> | ||
<TextField | ||
label="Redirect URL" | ||
type="url" | ||
id="url" | ||
name="url" | ||
placeholder="https://example.com/longlonglonglonglonglongurl" | ||
value={values.url} | ||
error={errors.url} | ||
onChange={handleChange} | ||
required | ||
/> | ||
</form> | ||
</div> | ||
<DialogFooter> | ||
<Button form="edit-link" type="submit"> | ||
Edit Link | ||
</Button> | ||
</DialogFooter> | ||
</DialogContent> | ||
); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import Services from '../../services'; | ||
import { BadRequestError } from '../../utils/errorHandler'; | ||
|
||
import type { ILinkForUpdate } from '@linx/shared'; | ||
import type { Reply, Request } from '../../types'; | ||
|
||
export default async function update(request: Request, reply: Reply) { | ||
const data = request.body as ILinkForUpdate; | ||
const user = request.user; | ||
|
||
const link = await Services.link.update(user.id, data); | ||
return reply.code(201).send({ | ||
success: true, | ||
message: 'Link modified successfully', | ||
data: { link: link }, | ||
}); | ||
} |
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