Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/pknu-wap/WAPP into featu…
Browse files Browse the repository at this point in the history
…re/jaino/#117
  • Loading branch information
jeongjaino committed Mar 7, 2024
2 parents 1a2f12d + 90a052b commit 7871644
Show file tree
Hide file tree
Showing 28 changed files with 267 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion app/src/main/java/com/wap/wapp/navigation/WappNavHost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ fun WappNavHost(
navigateToSignUp = navController::navigateToSignUp,
)
signUpScreen(
navigateToNotice = navController::navigateToNotice,
navigateToNotice = {
navController.navigateToNotice(
navOptions { popUpTo(navController.graph.id) { inclusive = true } },
)
},
navigateToSignIn = navController::navigateToSignIn,
)
noticeScreen()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ interface AuthRepository {
suspend fun deleteUser(): Result<Unit>

suspend fun isUserSignIn(): Result<Boolean>

suspend fun checkMemberCode(code: String): Result<Boolean>
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ class AuthRepositoryImpl @Inject constructor(
override suspend fun deleteUser(): Result<Unit> = authDataSource.deleteUser()

override suspend fun isUserSignIn(): Result<Boolean> = authDataSource.isUserSignIn()

override suspend fun checkMemberCode(code: String): Result<Boolean> =
authDataSource.checkMemberCode(code)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ interface ManagementRepository {

suspend fun postManager(userId: String): Result<Unit>

suspend fun getManagementCode(code: String): Result<Boolean>
suspend fun checkManagementCode(code: String): Result<Boolean>

suspend fun deleteManager(userId: String): Result<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class ManagementRepositoryImpl @Inject constructor(
override suspend fun postManager(userId: String): Result<Unit> =
managementDataSource.postManager(userId)

override suspend fun getManagementCode(code: String): Result<Boolean> =
managementDataSource.getManagementCode(code)
override suspend fun checkManagementCode(code: String): Result<Boolean> =
managementDataSource.checkManagementCode(code)

override suspend fun deleteManager(userId: String): Result<Unit> =
managementDataSource.deleteManager(userId)
Expand Down
4 changes: 4 additions & 0 deletions core/designsystem/src/main/java/com/wap/designsystem/Color.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ val Gray95 = Color(0xFF959595)
val Gray82 = Color(0xFF828282)
val Gray7C = Color(0xFF7C7C7C)
val Gray4A = Color(0xFF49494A)
val Black20 = Color(0xFF202022)
val Black25 = Color(0xFF252424)
val Black42 = Color(0xFF424242)
val Black = Color(0xFF000000)
Expand All @@ -36,6 +37,7 @@ class WappColor(
white: Color = Color(0xFFFFFFFF),
black: Color = Color(0xFF000000),
backgroundBlack: Color = Color(0xFF131313),
black20: Color = Color(0xFF202022),
black25: Color = Color(0xFF252424),
black42: Color = Color(0xFF424242),
gray95: Color = Color(0xFF959595),
Expand All @@ -62,6 +64,8 @@ class WappColor(
private set
var backgroundBlack by mutableStateOf(backgroundBlack)
private set
var black20 by mutableStateOf(black20)
private set
var black25 by mutableStateOf(black25)
private set
var black42 by mutableStateOf(black42)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fun WappButton(
onClick = { onClick() },
enabled = isEnabled,
colors = ButtonDefaults.buttonColors(
contentColor = WappTheme.colors.black,
contentColor = WappTheme.colors.white,
containerColor = WappTheme.colors.yellow34,
disabledContentColor = WappTheme.colors.white,
disabledContainerColor = WappTheme.colors.grayA2,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.wap.wapp.core.domain.usecase.auth

import com.wap.wapp.core.data.repository.auth.AuthRepository
import com.wap.wapp.core.domain.model.CodeValidation
import javax.inject.Inject

class CheckMemberCodeUseCase @Inject constructor(
private val authRepository: AuthRepository,
) {
suspend operator fun invoke(code: String): Result<CodeValidation> = runCatching {
authRepository.checkMemberCode(code).fold(
onSuccess = { isValid ->
if (isValid) {
return@fold CodeValidation.VALID
}
CodeValidation.INVALID
},
onFailure = { CodeValidation.INVALID },
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class ValidateManagementCodeUseCase @Inject constructor(
class CheckManagementCodeUseCase @Inject constructor(
private val managementRepository: ManagementRepository,
private val userRepository: UserRepository,
) {
suspend operator fun invoke(code: String): Result<CodeValidation> = runCatching {
managementRepository.getManagementCode(code)
managementRepository.checkManagementCode(code)
.onSuccess { isValid ->
if (isValid.not()) { // 코드가 틀렸을 경우
return@runCatching CodeValidation.INVALID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ data class Survey(
return "방금"
} else if (duration.toMinutes() < 60) {
val leftMinutes = duration.toMinutes().toString()
return leftMinutes + "분 전 작성"
return leftMinutes + "분 전"
}

if (duration.toHours() < 24) {
val leftHours = duration.toHours().toString()
return leftHours + "시간 전 작성"
return leftHours + "시간 전"
}

if (duration.toDays() < 31) {
val leftDays = duration.toDays().toString()
return leftDays + "일 전 작성"
return leftDays + "일 전"
}

return surveyedAt.format(yyyyMMddFormatter) + " 작성"
return surveyedAt.format(yyyyMMddFormatter)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ interface AuthDataSource {
suspend fun deleteUser(): Result<Unit>

suspend fun isUserSignIn(): Result<Boolean>

suspend fun checkMemberCode(code: String): Result<Boolean>
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ package com.wap.wapp.core.network.source.auth

import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.FirebaseAuth.AuthStateListener
import com.google.firebase.firestore.FirebaseFirestore
import com.wap.wapp.core.network.constant.CODES_COLLECTION
import com.wap.wapp.core.network.utils.await
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.suspendCancellableCoroutine
import javax.inject.Inject

class AuthDataSourceImpl @Inject constructor(
private val firebaseAuth: FirebaseAuth,
private val firebaseFirestore: FirebaseFirestore,
) : AuthDataSource {
override suspend fun signOut(): Result<Unit> = runCatching {
firebaseAuth.signOut()
Expand Down Expand Up @@ -45,4 +48,13 @@ class AuthDataSourceImpl @Inject constructor(
}
}
}

override suspend fun checkMemberCode(code: String): Result<Boolean> = runCatching {
val result = firebaseFirestore.collection(CODES_COLLECTION)
.whereEqualTo("user", code)
.get()
.await()

result.isEmpty.not()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ interface ManagementDataSource {

suspend fun postManager(userId: String): Result<Unit>

suspend fun getManagementCode(code: String): Result<Boolean>
suspend fun checkManagementCode(code: String): Result<Boolean>

suspend fun deleteManager(userId: String): Result<Unit>
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ManagementDataSourceImpl @Inject constructor(
.await()
}

override suspend fun getManagementCode(code: String): Result<Boolean> = runCatching {
override suspend fun checkManagementCode(code: String): Result<Boolean> = runCatching {
val result = firebaseFirestore.collection(CODES_COLLECTION)
.whereEqualTo("management", code)
.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ import com.wap.wapp.feature.auth.R.string
internal fun SignInContent(
openSignInSheet: () -> Unit,
navigateToNotice: () -> Unit,
modifier: Modifier = Modifier,
) {
val scrollState = rememberScrollState()

Column(
verticalArrangement = Arrangement.Center,
modifier = Modifier
modifier = modifier
.fillMaxSize()
.padding(horizontal = 16.dp)
.verticalScroll(scrollState),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ internal fun SignInScreen(
}
},
navigateToNotice = { navigateToNotice() },
modifier = Modifier.addFocusCleaner(focusManager),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ import androidx.compose.material3.SnackbarHostState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
Expand All @@ -34,6 +37,7 @@ import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.wap.designsystem.WappTheme
import com.wap.designsystem.component.WappSubTopBar
import com.wap.designsystem.modifier.addFocusCleaner
Expand All @@ -43,6 +47,7 @@ import com.wap.wapp.feature.auth.R.drawable.ic_card
import com.wap.wapp.feature.auth.R.drawable.ic_door
import com.wap.wapp.feature.auth.R.string
import com.wap.wapp.feature.auth.signup.SignUpViewModel.SignUpEvent
import com.wap.wapp.feature.auth.signup.validation.CodeValidationDialog
import kotlinx.coroutines.flow.collectLatest

@Composable
Expand All @@ -68,11 +73,18 @@ internal fun SignUpScreen(
val snackBarHostState = remember { SnackbarHostState() }
val keyboardController = LocalSoftwareKeyboardController.current
val focusManager = LocalFocusManager.current
var showCodeValidationDialog by remember { mutableStateOf(false) }

LaunchedEffect(true) {
viewModel.signUpEventFlow.collectLatest {
when (it) {
is SignUpEvent.Success -> navigateToNotice()
is SignUpEvent.SignUpSuccess -> navigateToNotice()

is SignUpEvent.ValidateUserInformationSuccess -> {
showCodeValidationDialog = true
}

is SignUpEvent.CheckMemberCodeSuccess -> viewModel.postUserProfile()

is SignUpEvent.Failure ->
snackBarHostState.showSnackbar(message = it.throwable.toSupportingText())
Expand All @@ -92,6 +104,20 @@ internal fun SignUpScreen(
.addFocusCleaner(focusManager)
.padding(paddingValue),
) {
if (showCodeValidationDialog) {
CodeValidationDialog(
code = viewModel.memberCode.collectAsStateWithLifecycle().value,
setValidationCode = viewModel::setWapMemberCode,
onConfirmRequest = viewModel::checkMemberCode,
onDismissRequest = { showCodeValidationDialog = false },
isError = viewModel.isError.collectAsStateWithLifecycle().value,
supportingText =
stringResource(
viewModel.errorSupportingText.collectAsStateWithLifecycle().value,
),
)
}

WappSubTopBar(
modifier = Modifier
.fillMaxWidth()
Expand Down Expand Up @@ -189,7 +215,7 @@ internal fun SignUpScreen(
Spacer(modifier = Modifier.weight(1f))

Button(
onClick = { viewModel.postUserProfile() },
onClick = { viewModel.validateUserInformation() },
modifier = Modifier
.fillMaxWidth()
.height(48.dp),
Expand Down
Loading

0 comments on commit 7871644

Please sign in to comment.