@@ -258,6 +258,53 @@ export function* signUp(action: MyAction): Generator<any, void, any> {
258258 }
259259}
260260
261+ /**
262+ * Request for new mechanic signup
263+
264+ * @payload {string} payload.name - User name
265+ * @payload {string} payload.email - User email
266+ * @payload {string} payload.number - User number
267+ * @payload {string} payload.mechanic_code - User mechanic code
268+ * @payload {string} payload.password - User password
269+ * @payload {Function} payload.callback - Callback method
270+ */
271+ export function * signUpMechanic ( action : MyAction ) : Generator < any , void , any > {
272+ const { name, email, number, mechanic_code, password, callback } = action . payload ;
273+ let receivedResponse : Partial < Response > = { } ;
274+ try {
275+ yield put ( { type : actionTypes . FETCHING_DATA } ) ;
276+
277+ const postUrl = APIService . WORKSHOP_SERVICE + requestURLS . SIGNUP_MECHANIC ;
278+ const headers = {
279+ "Content-Type" : "application/json" ,
280+ } ;
281+ // remove special chars from number
282+ let cleanedNumber = number . replace ( / [ ^ 0 - 9 + ] / g, "" ) ;
283+ console . log ( "number" , cleanedNumber ) ;
284+ const responseJSON = yield fetch ( postUrl , {
285+ headers,
286+ method : "POST" ,
287+ body : JSON . stringify ( {
288+ name : name ,
289+ email : email ,
290+ number : cleanedNumber ,
291+ mechanic_code : mechanic_code ,
292+ password : password ,
293+ } ) ,
294+ } ) . then ( ( response : Response ) => {
295+ receivedResponse = response ;
296+ return response . json ( ) ;
297+ } ) ;
298+
299+ yield put ( { type : actionTypes . FETCHED_DATA , payload : receivedResponse } ) ;
300+ if ( receivedResponse . ok ) callback ( responseTypes . SUCCESS , responseJSON . message ) ;
301+ else callback ( responseTypes . FAILURE , responseJSON . message || SIGN_UP_FAILED ) ;
302+ } catch ( e ) {
303+ yield put ( { type : actionTypes . FETCHED_DATA , payload : receivedResponse } ) ;
304+ callback ( responseTypes . FAILURE , SIGN_UP_FAILED ) ;
305+ }
306+ }
307+
261308/**
262309 * Send OTP for forgot password
263310
@@ -548,6 +595,7 @@ export function* userActionWatcher() {
548595 yield takeLatest ( actionTypes . VALIDATE_ACCESS_TOKEN , validateAccessToken ) ;
549596 yield takeLatest ( actionTypes . UNLOCK_USER , unlock ) ;
550597 yield takeLatest ( actionTypes . SIGN_UP , signUp ) ;
598+ yield takeLatest ( actionTypes . SIGN_UP_MECHANIC , signUpMechanic ) ;
551599 yield takeLatest ( actionTypes . VERIFY_OTP , verifyOTP ) ;
552600 yield takeLatest ( actionTypes . FORGOT_PASSWORD , forgotPassword ) ;
553601 yield takeLatest ( actionTypes . RESET_PASSWORD , resetPassword ) ;
0 commit comments