however, employer can't let me do the project illegally because I suddenly loss H1B that they have spent money and efforts to get it.
-If you lost your H1 status and that means you can not work for the employer legally. Then, how can the employer make trouble to you? Also, your H4 appliciton may take several months to be aprpoved, so you can tell the employer in advance that you will resign. So, how can the employer bother you? You are legally present during your H4 is pending even if you do not have a job.