-
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.
feat: support modify repo description
- Loading branch information
1 parent
fb2fc8d
commit ff0ae6b
Showing
3 changed files
with
178 additions
and
131 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,68 @@ | ||
'use client'; | ||
import { Button, Modal, Textarea } from '@mantine/core'; | ||
import { useDisclosure } from '@mantine/hooks'; | ||
import { GithubAPI, IGithubRepository } from '@shared/github-api'; | ||
import { useRequest } from 'ahooks'; | ||
import { useEffect, useState } from 'react'; | ||
import toast from 'react-hot-toast'; | ||
|
||
interface DeleteModalProps { | ||
accessToken: string; | ||
description?: string; | ||
repoItem: IGithubRepository; | ||
} | ||
|
||
export default function DescriptionModal({ description = '', accessToken, repoItem }: DeleteModalProps) { | ||
const [opened, { open, close }] = useDisclosure(false); | ||
const [value, setValue] = useState(''); | ||
|
||
useEffect(() => { | ||
setValue(description); | ||
}, [description]); | ||
|
||
const { run, loading, cancel } = useRequest( | ||
async () => { | ||
await GithubAPI.repo.patchRepo({ | ||
auth: accessToken, | ||
repo: repoItem.name, | ||
owner: repoItem.owner.login, | ||
schema: { | ||
description: value | ||
} | ||
}); | ||
toast.success('Change the repository description successfully'); | ||
setValue(value); | ||
}, | ||
{ | ||
manual: true | ||
} | ||
); | ||
|
||
const onClose = () => { | ||
cancel(); | ||
close(); | ||
}; | ||
|
||
return ( | ||
<> | ||
<Modal opened={opened} onClose={onClose} title="Modify the description:" centered> | ||
{/* Modal content */} | ||
<Textarea value={value} onChange={(e) => setValue(e.target.value)} className="pb-12" rows={4} /> | ||
<div> | ||
<div className="mt-4 flex justify-end gap-2 items-center"> | ||
<Button variant="outline" size="sm" onClick={onClose}> | ||
Cancel | ||
</Button> | ||
<Button size="sm" onClick={run} disabled={loading} loading={loading}> | ||
Confirm | ||
</Button> | ||
</div> | ||
</div> | ||
</Modal> | ||
|
||
<div className="cursor-pointer" onClick={open}> | ||
{value} | ||
</div> | ||
</> | ||
); | ||
} |
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