-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(admin): add update prompt function
- Loading branch information
Showing
11 changed files
with
284 additions
and
56 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
packages/frontend/admin/src/modules/ai/discard-changes.tsx
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,44 @@ | ||
import { Button } from '@affine/admin/components/ui/button'; | ||
import { | ||
Dialog, | ||
DialogContent, | ||
DialogDescription, | ||
DialogFooter, | ||
DialogHeader, | ||
DialogTitle, | ||
} from '@affine/admin/components/ui/dialog'; | ||
|
||
export const DiscardChanges = ({ | ||
open, | ||
onClose, | ||
onConfirm, | ||
onOpenChange, | ||
}: { | ||
open: boolean; | ||
onClose: () => void; | ||
onConfirm: () => void; | ||
onOpenChange: (open: boolean) => void; | ||
}) => { | ||
return ( | ||
<Dialog open={open} onOpenChange={onOpenChange}> | ||
<DialogContent className="sm:w-[460px]"> | ||
<DialogHeader> | ||
<DialogTitle className="leading-7">Discard Changes</DialogTitle> | ||
<DialogDescription className="leading-6"> | ||
Changes to this prompt will not be saved. | ||
</DialogDescription> | ||
</DialogHeader> | ||
<DialogFooter> | ||
<div className="flex justify-end items-center w-full space-x-4"> | ||
<Button type="button" onClick={onClose} variant="outline"> | ||
<span>Cancel</span> | ||
</Button> | ||
<Button type="button" onClick={onConfirm} variant="destructive"> | ||
<span>Discard</span> | ||
</Button> | ||
</div> | ||
</DialogFooter> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { useAsyncCallback } from '@affine/core/hooks/affine-async-hooks'; | ||
import { | ||
useMutateQueryResource, | ||
useMutation, | ||
} from '@affine/core/hooks/use-mutation'; | ||
import { useQuery } from '@affine/core/hooks/use-query'; | ||
import { getPromptsQuery, updatePromptMutation } from '@affine/graphql'; | ||
import { toast } from 'sonner'; | ||
|
||
import type { Prompt } from './prompts'; | ||
|
||
export const usePrompt = () => { | ||
const { data } = useQuery({ | ||
query: getPromptsQuery, | ||
}); | ||
|
||
const { trigger } = useMutation({ | ||
mutation: updatePromptMutation, | ||
}); | ||
|
||
const revalidate = useMutateQueryResource(); | ||
|
||
const updatePrompt = useAsyncCallback( | ||
async ({ | ||
name, | ||
messages, | ||
}: { | ||
name: string; | ||
messages: Prompt['messages']; | ||
}) => { | ||
await trigger({ | ||
name, | ||
messages, | ||
}) | ||
.then(async () => { | ||
await revalidate(getPromptsQuery); | ||
toast.success('Prompt updated successfully'); | ||
}) | ||
.catch(e => { | ||
toast(e.message); | ||
console.error(e); | ||
}); | ||
}, | ||
[revalidate, trigger] | ||
); | ||
|
||
return { | ||
prompts: data.listCopilotPrompts, | ||
updatePrompt, | ||
}; | ||
}; |
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.