-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
17 changed files
with
1,110 additions
and
716 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 |
---|---|---|
@@ -1,35 +1,42 @@ | ||
import { BranchAvailable } from '@/api/types/branch'; | ||
|
||
function formatLocalDate() { | ||
const now = new Date(); | ||
const offset = now.getTimezoneOffset() * 60000; | ||
const localISOTime = new Date(now.getTime() - offset).toISOString().slice(0, -1); | ||
return localISOTime.split('.')[0]; | ||
} | ||
|
||
export const getOfficeAvailable = async (name: string): Promise<{ data: BranchAvailable }> => { | ||
try { | ||
const backendUrl = process.env.NEXT_PUBLIC_BASE_URL; | ||
const now = formatLocalDate(); | ||
console.log(encodeURIComponent(name)); | ||
const token = document.cookie.replace(/(?:(?:^|.*;\s*)token\s*=\s*([^;]*).*$)|^.*$/, "$1"); | ||
const response = await fetch(`${backendUrl}branches/${encodeURIComponent(name)}/space?now=${encodeURIComponent(now)}`, { | ||
const now = new Date(); | ||
const offset = now.getTimezoneOffset() * 60000; | ||
const localISOTime = new Date(now.getTime() - offset).toISOString().slice(0, -1); | ||
return localISOTime.split('.')[0]; | ||
} | ||
|
||
export const getOfficeAvailable = async ( | ||
name: string | ||
): Promise<{ data: BranchAvailable }> => { | ||
try { | ||
const backendUrl = process.env.NEXT_PUBLIC_BASE_URL; | ||
const now = formatLocalDate(); | ||
|
||
const token = document.cookie.replace( | ||
/(?:(?:^|.*;\s*)token\s*=\s*([^;]*).*$)|^.*$/, | ||
'$1' | ||
); | ||
const response = await fetch( | ||
`${backendUrl}branches/${encodeURIComponent(name)}/space?now=${encodeURIComponent(now)}`, | ||
{ | ||
method: 'GET', | ||
headers: { | ||
'Authorization': `Bearer ${token}`, | ||
Authorization: `Bearer ${token}`, | ||
'Content-Type': 'application/json' | ||
}, | ||
cache: 'no-store' | ||
}); | ||
if (!response.ok) { | ||
throw new Error('Failed to fetch branch information'); | ||
} | ||
const data: { data: BranchAvailable } = await response.json(); | ||
console.log(data); | ||
return data; | ||
} catch (error) { | ||
console.error('Error fetching branch info:', error); | ||
throw error; | ||
); | ||
if (!response.ok) { | ||
throw new Error('Failed to fetch branch information'); | ||
} | ||
}; | ||
|
||
const data: { data: BranchAvailable } = await response.json(); | ||
|
||
return data; | ||
} catch (error) { | ||
console.error('Error fetching branch info:', error); | ||
throw error; | ||
} | ||
}; |
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
Oops, something went wrong.