-
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.
Refactored chat interface and updated employee form
1. Updated the chat interface to include sender information in the `chatStore`. The `Prompt` interface was renamed to `Message` and a `sender` field was added. The `addPrompt` function was also updated to `addMessage`, now taking a `sender` and `text` as parameters. 2. Refactored the `EmployeeForm` component to replace the `orgCategoryStore` with the `positionStore`. 3. Renamed `Chat.vue` to `ChatAssistant.vue` and updated the component to display messages in a card format with sender information. Added functionality to automatically scroll to the most recent message. 4. Added `Position` interface in `officeFrameTypes.ts`. 5. Created a new `positionStore` for handling position related data. 6. Updated the router configuration to reflect the new `ChatAssistant` component name. Please note, the `positionStore` is a placeholder and its methods and calls need to be properly implemented to function correctly.
- Loading branch information
Showing
6 changed files
with
162 additions
and
44 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
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 |
---|---|---|
@@ -1,53 +1,53 @@ | ||
import { defineStore } from 'pinia'; | ||
import { ref } from 'vue'; | ||
|
||
interface Prompt { | ||
interface Message { | ||
id: number; | ||
sender: string; | ||
text: string; | ||
} | ||
|
||
interface Chat { | ||
id: number; | ||
content: string; | ||
prompts: Prompt[]; | ||
messages: Message[]; | ||
} | ||
|
||
export const useChatStore = defineStore('chatStore', () => { | ||
const chats = ref<Chat[]>([]); | ||
const currentChat = ref<Chat>({ | ||
id: Date.now(), | ||
content: '', | ||
prompts: [], | ||
messages: [], | ||
}); | ||
|
||
const addPrompt = (prompt: string) => { | ||
currentChat.value.prompts.push({ id: Date.now(), text: prompt }); | ||
}; | ||
|
||
const addContent = (content: string) => { | ||
currentChat.value.content += content; | ||
const addMessage = (sender: string, text: string) => { | ||
currentChat.value.messages.push({ | ||
id: Date.now(), | ||
sender, | ||
text, | ||
}); | ||
}; | ||
|
||
const saveChat = () => { | ||
chats.value.push({ ...currentChat.value, id: Date.now() }); | ||
currentChat.value.content = ''; | ||
currentChat.value.prompts = []; | ||
chats.value.push({ ...currentChat.value }); | ||
currentChat.value = { | ||
id: Date.now(), | ||
messages: [], | ||
}; | ||
}; | ||
|
||
const dummyApiRequest = (prompt: string): Promise<string> => { | ||
return new Promise((resolve) => { | ||
setTimeout(() => { | ||
resolve(`Bot: Response to "${prompt}"`); | ||
resolve(`Response to "${prompt}"`); | ||
}, 1000); | ||
}); | ||
}; | ||
|
||
return { | ||
chats, | ||
currentChat, | ||
addPrompt, | ||
addContent, | ||
addMessage, | ||
saveChat, | ||
dummyApiRequest, | ||
}; | ||
}); | ||
}); |
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,94 @@ | ||
import {defineStore} from 'pinia'; | ||
import {ref, computed} from 'vue'; | ||
import apiClient, {setupApiClient} from '../../api/apiClient'; | ||
import {ApiFormResponse, ApiViewPageResponse} from "../../types"; | ||
import {Organization, OrganizationSave, Position} from "../../types/officeFrameTypes"; | ||
|
||
export const usePositionStore = defineStore('positionStore', () => { | ||
const apiViewResponse = ref<ApiViewPageResponse<Position> | null>(null); | ||
const apiFormResponse = ref<ApiFormResponse | null>(null); | ||
|
||
const getEntries = computed(() => { | ||
return apiViewResponse.value?.viewData.entries || []; | ||
}); | ||
|
||
const getCurrent = computed(() => { | ||
const defaultData = { | ||
regDate: '', | ||
lastModifiedDate: '', | ||
identifier: '' | ||
}; | ||
return apiFormResponse.value?.docData || defaultData; | ||
}); | ||
|
||
const getPagination = computed(() => { | ||
if (!apiViewResponse.value) { | ||
return { | ||
page: 1, | ||
pageSize: 10, | ||
itemCount: 0, | ||
pageCount: 1, | ||
showSizePicker: true, | ||
pageSizes: [10, 20, 30, 40] | ||
}; | ||
} | ||
|
||
const { viewData } = apiViewResponse.value; | ||
return { | ||
page: viewData.pageNum, | ||
pageSize: viewData.pageSize, | ||
itemCount: viewData.count, | ||
pageCount: viewData.maxPage, | ||
showSizePicker: true, | ||
pageSizes: [10, 20, 30, 40] | ||
}; | ||
}); | ||
|
||
const fetchOrgCategories = async (page = 1, pageSize = 10) => { | ||
const response = await apiClient.get(`/positions?page=${page}&size=${pageSize}`); | ||
if (response && response.data && response.data.payload) { | ||
apiViewResponse.value = response.data.payload; | ||
} else { | ||
throw new Error('Invalid API response structure'); | ||
} | ||
}; | ||
|
||
const fetchOrgCategory = async (id: string) => { | ||
const response = await apiClient.get(`/positions/${id}`); | ||
if (response && response.data && response.data.payload) { | ||
apiFormResponse.value = response.data.payload; | ||
} else { | ||
throw new Error('Invalid API response structure'); | ||
} | ||
}; | ||
|
||
const updateCurrent = (data: Organization, actions: any = {}) => { | ||
apiFormResponse.value = { | ||
docData: data, | ||
actions: actions | ||
}; | ||
}; | ||
|
||
const save = async (data: OrganizationSave, id?: string) => { | ||
const response = await apiClient.post(`/positions/${id}`, data); | ||
if (response && response.data) { | ||
const { docData } = response.data; | ||
updateCurrent(docData, {}); | ||
return docData; | ||
} else { | ||
throw new Error('Invalid API response structure'); | ||
} | ||
}; | ||
|
||
return { | ||
apiViewResponse, | ||
apiFormResponse, | ||
setupApiClient, | ||
fetchAll: fetchOrgCategories, | ||
fetch: fetchOrgCategory, | ||
save, | ||
getEntries, | ||
getPagination, | ||
getCurrent | ||
}; | ||
}); |
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