Ignore:
Timestamp:
02/26/25 14:27:26 (6 weeks ago)
Author:
Naum Shapkarovski <naumshapkarovski@…>
Branches:
main
Children:
3c5302a
Parents:
057453c
Message:

chore

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sections/user/customer-quick-edit-form.tsx

    r057453c r299af01  
    1414import DialogContent from '@mui/material/DialogContent';
    1515// types
    16 import { Customer, customerSchema } from 'src/schemas';
     16import { Customer, updateCustomerSchema } from 'src/schemas';
    1717// assets
    1818import { countries } from 'src/assets/data';
     
    2121import { useSnackbar } from 'src/components/snackbar';
    2222import FormProvider, { RHFSelect, RHFTextField, RHFAutocomplete } from 'src/components/hook-form';
    23 import { doc, setDoc } from 'firebase/firestore';
    24 import { db } from 'src/lib/firebase';
    25 import { mutate } from 'swr';
    26 import { collections } from 'src/lib/firestore';
     23import { updateCustomer } from 'src/api/customer';
    2724
    2825// ----------------------------------------------------------------------
     
    5855      },
    5956      vatNumber: currentCustomer?.vatNumber || '',
    60       companyId: currentCustomer?.companyId || '',
    6157      companyNumber: currentCustomer?.companyNumber || '',
    6258      id: currentCustomer?.id || '',
     
    6864
    6965  const methods = useForm({
    70     resolver: zodResolver(customerSchema),
     66    resolver: zodResolver(updateCustomerSchema),
    7167    defaultValues,
    7268  });
     
    8076  const onSubmit = handleSubmit(async (data) => {
    8177    try {
     78      console.log('currentCustomer', currentCustomer);
    8279      if (!currentCustomer) return;
    83       // await new Promise((resolve) => setTimeout(resolve, 500));
    84 
    85       const docRef = doc(db, 'customers', currentCustomer.id!);
    86       await setDoc(docRef, data, { merge: true });
    87       mutate(collections.customer);
     80      console.log('data', data);
     81      await updateCustomer(currentCustomer.id!, data);
    8882
    8983      reset();
     
    9387    } catch (error) {
    9488      console.error(error);
     89      enqueueSnackbar('Update failed!', { variant: 'error' });
    9590    }
    9691  });
Note: See TracChangeset for help on using the changeset viewer.