@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.
@@ -232,7 +232,8 @@ function ApplyLeaveView({
232
232
  onSuccess
233
233
  }) {
234
234
  const {
235
- api
235
+ api,
236
+ schoolCode
236
237
  } = useERP();
237
238
  const Calendar = useMemo(() => tryGetCalendar(), []);
238
239
  const [reason, setReason] = useState('');
@@ -270,7 +271,7 @@ function ApplyLeaveView({
270
271
  setFileName(file.name);
271
272
  setBusy(true);
272
273
  try {
273
- const res = await uploadLeaveFile(api, file);
274
+ const res = await uploadLeaveFile(api, file, schoolCode);
274
275
  if (res?.Status === 'Success' && res?.data) {
275
276
  setFilePath(res.data);
276
277
  } else {
@@ -286,7 +287,7 @@ function ApplyLeaveView({
286
287
  setBusy(false);
287
288
  setUploadOpen(false);
288
289
  }
289
- }, [api]);
290
+ }, [api, schoolCode]);
290
291
  const pickCamera = useCallback(async () => {
291
292
  let picker = null;
292
293
  try {
@@ -316,7 +317,7 @@ function ApplyLeaveView({
316
317
  setFileName(file.name);
317
318
  setBusy(true);
318
319
  try {
319
- const res = await uploadLeaveFile(api, file);
320
+ const res = await uploadLeaveFile(api, file, schoolCode);
320
321
  if (res?.Status === 'Success' && res?.data) {
321
322
  setFilePath(res.data);
322
323
  } else {
@@ -332,7 +333,7 @@ function ApplyLeaveView({
332
333
  setBusy(false);
333
334
  setUploadOpen(false);
334
335
  }
335
- }, [api]);
336
+ }, [api, schoolCode]);
336
337
  const submit = useCallback(async () => {
337
338
  const missing = [];
338
339
  if (!reason) missing.push('reason');
@@ -1,6 +1,14 @@
1
1
  "use strict";
2
2
 
3
3
  import { endpoints } from "../../../core/api/endpoints.js";
4
+ function buildUploadFilePath(relativePath, schoolCode) {
5
+ const normalized = String(relativePath).replace(/\\/g, '/').replace(/^\/+/, '');
6
+ if (!schoolCode) {
7
+ return normalized;
8
+ }
9
+ const withoutUploads = normalized.replace(/^uploads\//i, '');
10
+ return `school_${schoolCode}/${withoutUploads}`;
11
+ }
4
12
  export async function fetchLeaveRequests(api, params) {
5
13
  const page = params.page ?? 1;
6
14
  const perPage = params.perPage ?? 10;
@@ -14,14 +22,14 @@ export async function fetchLeaveTypes(api) {
14
22
  const res = await api.get(endpoints.leaveRequest.leaveTypes);
15
23
  return res.data;
16
24
  }
17
- export async function uploadLeaveFile(api, file) {
25
+ export async function uploadLeaveFile(api, file, schoolCode) {
18
26
  const formData = new FormData();
19
27
  formData.append('file', {
20
28
  uri: file.uri,
21
29
  name: file.name,
22
30
  type: file.type
23
31
  });
24
- formData.append('filepath', 'uploads/staff/leave/');
32
+ formData.append('filepath', buildUploadFilePath('uploads/staff/leave/', schoolCode));
25
33
  const res = await api.post(endpoints.assignment.uploadFile, formData, {
26
34
  headers: {
27
35
  'Content-Type': 'multipart/form-data'