-
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.
- Loading branch information
1 parent
9861184
commit 442462a
Showing
4 changed files
with
161 additions
and
103 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,69 @@ | ||
'use client'; | ||
import { Tooltip } from '@mantine/core'; | ||
import { cn } from '@shared/fc'; | ||
import { GithubAPI, IUserRepoList } from '@shared/github-api'; | ||
import { useRequest } from 'ahooks'; | ||
import { ArchiveIcon } from 'lucide-react'; | ||
import toast from 'react-hot-toast'; | ||
import ConfirmModal from '../ConfirmModal'; | ||
|
||
interface ArchiveModalProps { | ||
selectedRows: IUserRepoList; | ||
mutate: (items: any) => void; | ||
accessToken: string; | ||
} | ||
|
||
export default function ArchiveModal({ selectedRows, mutate, accessToken }: ArchiveModalProps) { | ||
const { run, loading } = useRequest( | ||
() => { | ||
return Promise.allSettled( | ||
selectedRows | ||
.filter((i) => i.archived !== true) | ||
.map((i) => | ||
GithubAPI.repo | ||
.patchRepo({ | ||
auth: accessToken, | ||
owner: i.owner.login, | ||
repo: i.name, | ||
schema: { | ||
archived: true | ||
} | ||
}) | ||
.then(() => { | ||
toast.success(`Archived ${i.full_name}`); | ||
mutate((prevData: any) => { | ||
return prevData.map((item: any) => { | ||
if (item.id === i.id) { | ||
return { | ||
...item, | ||
archived: true | ||
}; | ||
} | ||
return item; | ||
}); | ||
}); | ||
}) | ||
.catch(() => { | ||
toast.error(`Failed to archived ${i.full_name}`); | ||
}) | ||
) | ||
); | ||
}, | ||
{ | ||
manual: true | ||
} | ||
); | ||
|
||
return ( | ||
<ConfirmModal title="Archive your selected repositories?" confirmFc={run} loading={loading}> | ||
<Tooltip label="batch archive"> | ||
<ArchiveIcon | ||
size={22} | ||
className={cn('text-orange-500 mt-[5px]', { | ||
hidden: selectedRows.filter((i) => i.archived !== true).length === 0 | ||
})} | ||
/> | ||
</Tooltip> | ||
</ConfirmModal> | ||
); | ||
} |
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