@ubkinfotech/tecaher-erp 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -237,7 +237,8 @@ function ApplyLeaveView({
237
237
  onSuccess
238
238
  }) {
239
239
  const {
240
- api
240
+ api,
241
+ schoolCode
241
242
  } = (0, _useERP.useERP)();
242
243
  const Calendar = (0, _react.useMemo)(() => tryGetCalendar(), []);
243
244
  const [reason, setReason] = (0, _react.useState)('');
@@ -275,7 +276,7 @@ function ApplyLeaveView({
275
276
  setFileName(file.name);
276
277
  setBusy(true);
277
278
  try {
278
- const res = await (0, _leaveRequestService.uploadLeaveFile)(api, file);
279
+ const res = await (0, _leaveRequestService.uploadLeaveFile)(api, file, schoolCode);
279
280
  if (res?.Status === 'Success' && res?.data) {
280
281
  setFilePath(res.data);
281
282
  } else {
@@ -291,7 +292,7 @@ function ApplyLeaveView({
291
292
  setBusy(false);
292
293
  setUploadOpen(false);
293
294
  }
294
- }, [api]);
295
+ }, [api, schoolCode]);
295
296
  const pickCamera = (0, _react.useCallback)(async () => {
296
297
  let picker = null;
297
298
  try {
@@ -321,7 +322,7 @@ function ApplyLeaveView({
321
322
  setFileName(file.name);
322
323
  setBusy(true);
323
324
  try {
324
- const res = await (0, _leaveRequestService.uploadLeaveFile)(api, file);
325
+ const res = await (0, _leaveRequestService.uploadLeaveFile)(api, file, schoolCode);
325
326
  if (res?.Status === 'Success' && res?.data) {
326
327
  setFilePath(res.data);
327
328
  } else {
@@ -337,7 +338,7 @@ function ApplyLeaveView({
337
338
  setBusy(false);
338
339
  setUploadOpen(false);
339
340
  }
340
- }, [api]);
341
+ }, [api, schoolCode]);
341
342
  const submit = (0, _react.useCallback)(async () => {
342
343
  const missing = [];
343
344
  if (!reason) missing.push('reason');
@@ -8,6 +8,14 @@ exports.fetchLeaveRequests = fetchLeaveRequests;
8
8
  exports.fetchLeaveTypes = fetchLeaveTypes;
9
9
  exports.uploadLeaveFile = uploadLeaveFile;
10
10
  var _endpoints = require("../../../core/api/endpoints");
11
+ function buildUploadFilePath(relativePath, schoolCode) {
12
+ const normalized = String(relativePath).replace(/\\/g, '/').replace(/^\/+/, '');
13
+ if (!schoolCode) {
14
+ return normalized;
15
+ }
16
+ const withoutUploads = normalized.replace(/^uploads\//i, '');
17
+ return `school_${schoolCode}/${withoutUploads}`;
18
+ }
11
19
  async function fetchLeaveRequests(api, params) {
12
20
  const page = params.page ?? 1;
13
21
  const perPage = params.perPage ?? 10;
@@ -21,14 +29,14 @@ async function fetchLeaveTypes(api) {
21
29
  const res = await api.get(_endpoints.endpoints.leaveRequest.leaveTypes);
22
30
  return res.data;
23
31
  }
24
- async function uploadLeaveFile(api, file) {
32
+ async function uploadLeaveFile(api, file, schoolCode) {
25
33
  const formData = new FormData();
26
34
  formData.append('file', {
27
35
  uri: file.uri,
28
36
  name: file.name,
29
37
  type: file.type
30
38
  });
31
- formData.append('filepath', 'uploads/staff/leave/');
39
+ formData.append('filepath', buildUploadFilePath('uploads/staff/leave/', schoolCode));
32
40
  const res = await api.post(_endpoints.endpoints.assignment.uploadFile, formData, {
33
41
  headers: {
34
42
  'Content-Type': 'multipart/form-data'