Skip to content

Commit

Permalink
[Feature] RegistrationScreen UI 로직 구현 (#31)
Browse files Browse the repository at this point in the history
* [Feat]: 회원가입 유즈케이스 구현

* [Feat]: userData 전송,저장 기능 구현

* [Feat]: 회원가입 관련 Type 구현

* [Feat]: 회원가입 기능 구현

* [Style]: 코드 포맷 수정
  • Loading branch information
jinuemong authored Jan 30, 2024
1 parent 16f4e51 commit 4fef053
Show file tree
Hide file tree
Showing 22 changed files with 533 additions and 241 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package ac.dnd.bookkeeping.android.domain.usecase.authentication

import ac.dnd.bookkeeping.android.domain.model.authentication.Register
import ac.dnd.bookkeeping.android.domain.repository.AuthenticationRepository
import javax.inject.Inject

class RegistrationUseCase @Inject constructor(
private val authenticationRepository: AuthenticationRepository
) {
suspend operator fun invoke(
socialId: Long,
email: String,
profileImageUrl: String,
name: String,
nickname: String,
gender: String,
birth: String
): Result<Register> {
return authenticationRepository.register(
socialId = socialId,
email = email,
profileImageUrl = profileImageUrl,
name = name,
nickname = nickname,
gender = gender,
birth = birth
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ class LoginMainViewModel @Inject constructor(

fun onIntent(intent: LoginMainIntent) {
when (intent) {
LoginMainIntent.Click -> {
loginFlow()
}
LoginMainIntent.Click -> loginFlow()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ fun NavGraphBuilder.loginOnBoardingDestination(
?.savedStateHandle
?.get<KakaoUserInformationModel>(LoginOnBoardingConstant.ROURE_ARGUMENT_USER_MODEL)
?: KakaoUserInformationModel(0L, "", "", "")
if (userModel.email.isEmpty()) appState.navController.popBackStack()

val viewModel: LoginOnBoardingViewModel = hiltViewModel()
if (userModel.email.isEmpty()) {
appState.navController.popBackStack()
} else {
viewModel.initKakaoUserInfo(userModel)
}

val model: LoginOnBoardingModel = let {
val state by viewModel.state.collectAsStateWithLifecycle()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
package ac.dnd.bookkeeping.android.presentation.ui.main.login.onboarding

sealed interface LoginOnBoardingEvent
import ac.dnd.bookkeeping.android.presentation.model.login.KakaoUserInformationModel

sealed interface LoginOnBoardingEvent {
data class Submit(
val kakaoUserModel: KakaoUserInformationModel
) : LoginOnBoardingEvent
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package ac.dnd.bookkeeping.android.presentation.ui.main.login.onboarding

sealed interface LoginOnBoardingIntent
sealed interface LoginOnBoardingIntent {
data object Click : LoginOnBoardingIntent
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import ac.dnd.bookkeeping.android.presentation.common.view.confirm.ConfirmButton
import ac.dnd.bookkeeping.android.presentation.common.view.confirm.ConfirmButtonProperties
import ac.dnd.bookkeeping.android.presentation.common.view.confirm.ConfirmButtonSize
import ac.dnd.bookkeeping.android.presentation.common.view.confirm.ConfirmButtonType
import ac.dnd.bookkeeping.android.presentation.model.login.KakaoUserInformationModel
import ac.dnd.bookkeeping.android.presentation.ui.main.ApplicationState
import ac.dnd.bookkeeping.android.presentation.ui.main.home.HomeConstant
import ac.dnd.bookkeeping.android.presentation.ui.main.login.LoginConstant
import ac.dnd.bookkeeping.android.presentation.ui.main.registration.main.RegistrationMainConstant
import ac.dnd.bookkeeping.android.presentation.ui.main.rememberApplicationState
import androidx.compose.animation.animateColorAsState
import androidx.compose.foundation.ExperimentalFoundationApi
Expand Down Expand Up @@ -43,6 +43,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavHostController
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.launch
import kotlinx.coroutines.plus
Expand All @@ -61,13 +62,10 @@ fun LoginOnBoardingScreen(
pageCount = { 3 }
)

fun navigateToHome() {
appState.navController.navigate(HomeConstant.ROUTE) {
popUpTo(LoginConstant.ROUTE) {
inclusive = true
}
}
fun navigateToRegistration(kakaoUserModel: KakaoUserInformationModel) {
appState.navController.sendKakaoUserModel(kakaoUserModel)
}

Box(
modifier = Modifier
.fillMaxSize()
Expand Down Expand Up @@ -125,7 +123,7 @@ fun LoginOnBoardingScreen(
.align(Alignment.BottomCenter)
.padding(25.dp),
onClick = {
navigateToHome()
intent(LoginOnBoardingIntent.Click)
}
) { style ->
Text(
Expand All @@ -137,7 +135,11 @@ fun LoginOnBoardingScreen(

LaunchedEffectWithLifecycle(event, handler) {
event.eventObserve { event ->

when (event) {
is LoginOnBoardingEvent.Submit -> {
navigateToRegistration(event.kakaoUserModel)
}
}
}
}
}
Expand All @@ -162,6 +164,16 @@ private fun LoginOnBoardingPage(
}
}

private fun NavHostController.sendKakaoUserModel(kakaoUserModel: KakaoUserInformationModel) {
currentBackStackEntry?.savedStateHandle?.apply {
set(
key = RegistrationMainConstant.ROURE_ARGUMENT_USER_MODEL,
value = kakaoUserModel
)
}
navigate(RegistrationMainConstant.CONTAIN_USER_MODEL)
}

@Preview
@Composable
fun LoginOnBoardingScreenPreview() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ac.dnd.bookkeeping.android.presentation.common.base.BaseViewModel
import ac.dnd.bookkeeping.android.presentation.common.util.coroutine.event.EventFlow
import ac.dnd.bookkeeping.android.presentation.common.util.coroutine.event.MutableEventFlow
import ac.dnd.bookkeeping.android.presentation.common.util.coroutine.event.asEventFlow
import ac.dnd.bookkeeping.android.presentation.model.login.KakaoUserInformationModel
import androidx.lifecycle.SavedStateHandle
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
Expand All @@ -23,7 +24,21 @@ class LoginOnBoardingViewModel @Inject constructor(
private val _event: MutableEventFlow<LoginOnBoardingEvent> = MutableEventFlow()
val event: EventFlow<LoginOnBoardingEvent> = _event.asEventFlow()

fun onIntent(intent: LoginOnBoardingIntent) {
private val _kakaoUserInfo: MutableStateFlow<KakaoUserInformationModel> =
MutableStateFlow(KakaoUserInformationModel(0L, "", "", ""))
private val kakaoUserInfo: StateFlow<KakaoUserInformationModel> = _kakaoUserInfo.asStateFlow()

fun initKakaoUserInfo(userModel: KakaoUserInformationModel) {
_kakaoUserInfo.value = userModel
}

fun onIntent(intent: LoginOnBoardingIntent) {
when (intent) {
LoginOnBoardingIntent.Click -> {
launch {
_event.emit(LoginOnBoardingEvent.Submit(kakaoUserInfo.value))
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ import ac.dnd.bookkeeping.android.presentation.ui.main.registration.Registration

object RegistrationMainConstant {
const val ROUTE: String = "${RegistrationConstant.ROUTE}/main"

const val ROURE_ARGUMENT_USER_MODEL = "kakaoUserModel"
const val CONTAIN_USER_MODEL = "${ROUTE}/{${ROURE_ARGUMENT_USER_MODEL}}"
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package ac.dnd.bookkeeping.android.presentation.ui.main.registration.main

import ac.dnd.bookkeeping.android.presentation.common.util.ErrorObserver
import ac.dnd.bookkeeping.android.presentation.model.login.KakaoUserInformationModel
import ac.dnd.bookkeeping.android.presentation.ui.main.ApplicationState
import ac.dnd.bookkeeping.android.presentation.ui.main.registration.RegistrationConstant
import ac.dnd.bookkeeping.android.presentation.ui.main.registration.RegistrationViewModel
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.NavGraphBuilder
Expand All @@ -15,20 +14,30 @@ fun NavGraphBuilder.registrationNamingDestination(
appState: ApplicationState
) {
composable(
route = RegistrationMainConstant.ROUTE
) { backStackEntry ->
val parentEntry = remember(backStackEntry) {
appState.navController.getBackStackEntry(RegistrationConstant.ROUTE)
}
val parentViewModel: RegistrationViewModel = hiltViewModel(parentEntry)
route = RegistrationMainConstant.CONTAIN_USER_MODEL
) {

val userModel = appState.navController.previousBackStackEntry
?.savedStateHandle
?.get<KakaoUserInformationModel>(RegistrationMainConstant.ROURE_ARGUMENT_USER_MODEL)
?: KakaoUserInformationModel(0L, "", "", "")

val viewModel: RegistrationMainViewModel = hiltViewModel()

if (userModel.email.isEmpty()) {
appState.navController.popBackStack()
} else {
LaunchedEffect(Unit) {
viewModel.initKakaoUserInfo(userModel)
}
}

val model: RegistrationMainModel = let {
val state by viewModel.state.collectAsStateWithLifecycle()
val errorType by viewModel.errorType.collectAsStateWithLifecycle()
val namingErrorType by viewModel.namingErrorType.collectAsStateWithLifecycle()
RegistrationMainModel(
state = state,
errorType = errorType
namingErrorType = namingErrorType
)
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ac.dnd.bookkeeping.android.presentation.ui.main.registration.main

import ac.dnd.bookkeeping.android.domain.model.error.ServerException

sealed interface RegistrationMainEvent {

sealed interface Check : RegistrationMainEvent {
Expand All @@ -9,7 +11,7 @@ sealed interface RegistrationMainEvent {

sealed interface Submit : RegistrationMainEvent {
data object Success : Submit
data object Failure : Submit
data object Error : Submit
data class Failure(val exception: ServerException) : Submit
data class Error(val exception: Throwable) : Submit
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package ac.dnd.bookkeeping.android.presentation.ui.main.registration.main

sealed interface RegistrationMainIntent {
data object OnCheckUserName : RegistrationMainIntent
data object OnClickSubmit : RegistrationMainIntent
data class OnCheckUserName(val name: String) : RegistrationMainIntent
data class OnClickSubmit(
val nickName: String,
val gender: String,
val birth: String
) : RegistrationMainIntent
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package ac.dnd.bookkeeping.android.presentation.ui.main.registration.main

import ac.dnd.bookkeeping.android.presentation.ui.main.registration.main.type.RegistrationMainNamingErrorType

data class RegistrationMainModel(
val state: RegistrationMainState,
val errorType: RegistrationMainErrorType
val namingErrorType: RegistrationMainNamingErrorType
)
Loading

0 comments on commit 4fef053

Please sign in to comment.