diff --git a/apps/client/src/common/api/ontimeApi.ts b/apps/client/src/common/api/ontimeApi.ts index d1b95123c..edf306862 100644 --- a/apps/client/src/common/api/ontimeApi.ts +++ b/apps/client/src/common/api/ontimeApi.ts @@ -265,17 +265,23 @@ export const uploadSheetClientFile = async (file: File) => { }; export const getSheetsAuthUrl = async () => { - const res = await axios.get(`${ontimeURL}/sheet-authurl`); - return res.data; + const response = await axios.get(`${ontimeURL}/sheet-authurl`); + return response.data; }; export const postPreviewSheet = async (id: string, worksheet: string) => { - const response = await axios.post(`${ontimeURL}/sheet-preview`, { id, worksheet }); + const response = await axios.post(`${ontimeURL}/sheet-preview`, { + id, + worksheet, + }); return response.data.data; }; export const postPushSheet = async (id: string, worksheet: string) => { - const response = await axios.post(`${ontimeURL}/sheet-push`, { id, worksheet }); + const response = await axios.post(`${ontimeURL}/sheet-push`, { + id, + worksheet, + }); return response.data.data; }; @@ -284,9 +290,9 @@ export const postPushSheet = async (id: string, worksheet: string) => { * @return {Promise} */ export const getSheetState = async (id: string, worksheet: string): Promise => { - const res = await axios.post(`${ontimeURL}/sheet-state`, { + const response = await axios.post(`${ontimeURL}/sheet-state`, { id, worksheet, }); - return res.data; + return response.data; }; diff --git a/apps/client/src/features/modals/sheets-modal/SheetsModal.tsx b/apps/client/src/features/modals/sheets-modal/SheetsModal.tsx index a8ba83ae6..31acb3586 100644 --- a/apps/client/src/features/modals/sheets-modal/SheetsModal.tsx +++ b/apps/client/src/features/modals/sheets-modal/SheetsModal.tsx @@ -16,11 +16,12 @@ import { Select, } from '@chakra-ui/react'; import { useQueryClient } from '@tanstack/react-query'; -import { OntimeRundown, ProjectData, UserFields } from 'ontime-types'; +import { OntimeRundown, ProjectData, SheetState, UserFields } from 'ontime-types'; import { PROJECT_DATA, RUNDOWN, USERFIELDS } from '../../../common/api/apiConstants'; import { maybeAxiosError } from '../../../common/api/apiUtils'; import { + getSheetState, getSheetsAuthUrl, patchData, postPreviewSheet, @@ -52,18 +53,25 @@ export default function SheetsModal(props: SheetsModalProps) { const fileInputRef = useRef(null); const sheetRef = useRef(null); const worksheetRef = useRef(null); - const [sheetId, setSheetId] = useState(null); - const [worksheet, setWorksheet] = useState(null); + // const [sheetId, setSheetId] = useState(null); + // const [worksheet, setWorksheet] = useState(null); - const { data: sheetState, refetch } = useSheetState(sheetId, worksheet); + // const { data: sheetState, refetch } = useSheetState(sheetId, worksheet); - const onChange = () => { - if (sheetRef.current?.value && sheetRef.current?.value.length > 43 && worksheetRef.current) { - setSheetId(sheetRef.current.value); - setWorksheet(worksheetRef.current.value); - refetch(); - } + const [sheetState, setState] = useState({ + secret: false, + auth: false, + id: false, + worksheet: false, + worksheetOptions: [], + }); + + //TODO: soulde the be a button like now or on change? + const testId = async () => { + console.log('test', sheetRef.current?.value, worksheetRef.current?.value); + setState(await getSheetState(sheetRef.current?.value ?? '', worksheetRef.current?.value ?? '')); }; + const handleClose = () => { setRundown(null); setProject(null); @@ -87,12 +95,14 @@ export default function SheetsModal(props: SheetsModalProps) { // TODO: show this in the modal console.error(error); } - refetch(); + // refetch(); + setState(await getSheetState(sheetRef.current?.value ?? '', worksheetRef.current?.value ?? '')); }; useEffect(() => { if (isOpen) { - refetch(); + getSheetState(sheetRef.current?.value ?? '', worksheetRef.current?.value ?? '').then((data) => setState(data)); + // refetch(); } return () => { // Alex: This function will be run when the component unmounts @@ -214,11 +224,13 @@ export default function SheetsModal(props: SheetsModalProps) { ref={sheetRef} id='sheetid' size='sm' - onChange={onChange} variant='ontime-filled-on-light' disabled={!sheetState?.auth} /> + Push data @@ -253,7 +265,7 @@ export default function SheetsModal(props: SheetsModalProps) { disabled={!sheetState?.worksheet} variant='ontime-ghosted-on-light' padding='0 2em' - onClick={handlePushData} + onClick={handlePullData} > Pull data diff --git a/apps/server/src/controllers/ontimeController.ts b/apps/server/src/controllers/ontimeController.ts index 9c970e15a..24f733ce0 100644 --- a/apps/server/src/controllers/ontimeController.ts +++ b/apps/server/src/controllers/ontimeController.ts @@ -464,7 +464,7 @@ export const postNew: RequestHandler = async (req, res) => { */ export async function previewSheet(req, res) { try { - const { id, worksheet } = req.data; + const { id, worksheet } = req.body; const data = await Sheet.pull(id, worksheet); res.status(200).send(data); } catch (error) { @@ -528,7 +528,6 @@ export async function sheetAuthUrl(req, res) { * @method POST */ export const getSheetState = async (req, res) => { - console.log('getstate', req.body); const { id, worksheet } = req.body; res.status(200).send(await Sheet.getSheetState(id, worksheet)); }; diff --git a/apps/server/src/controllers/ontimeController.validate.ts b/apps/server/src/controllers/ontimeController.validate.ts index fa711c5e6..e61a55598 100644 --- a/apps/server/src/controllers/ontimeController.validate.ts +++ b/apps/server/src/controllers/ontimeController.validate.ts @@ -155,8 +155,8 @@ export const validatePatchProjectFile = [ //TODO: is thise correct export const validateSheetParams = [ - body('sheetid').isString().optional({ nullable: false }), - body('worksheet').isString().optional({ nullable: false }), + body('id').exists().isString(), + body('worksheet').exists().isString(), (req, res, next) => { const errors = validationResult(req); if (!errors.isEmpty()) return res.status(422).json({ errors: errors.array() });